Image resize in PHP

Recently I have been working on a Content Management System for Toshiba TEC Australia. Basically we have built a recipe printer kiosk application that allows you to browse recipes, share them on social networks, email, and also to print them in-store, leveraging a serial printer installed on the kiosk.

The CMS I’ve ben working on lets you add new recipes, modify existing ones, manage categories etc.. I built it in Flex using PHP as a server-side language. Every recipe can have an image associated with it, so in my CMS I have provided a form to handle file upload, and delegated the resize of the image to PHP.

I found this great class, SimpleImage that allows you to resize and scale images, and I have added a little function to it, as I thought there was something missing:

function resizeWH($maxWidth, $maxHeight)


$currentWidth = $this->getWidth();

$currentHeight = $this->getHeight();

if($currentWidth > $currentHeight)

$this -> resizeToWidth($maxWidth);


$this -> resizeToHeight($maxHeight);


You basically specify the maximum width and height you want your image to be resized at, and the function just determines if your image has a landscape or portrait orientation, so it can resize it without changing it’s aspect ratio.


Build and install your AIR for iOS apps with a single bash script

Every one of us, who has developed an application for iOS using Adobe AIR, knows how long and painful is the process of testing the app on a iDevice. If you develop native obj-C applications using Xcode you can simply hit a button and the IDE will just build it and install it for you. The workflow for Flash developers instead, as suggested by Adobe itself is the following:

  1. Build the app using the launch method “On device” (either Standard or Fast)
  2. Uninstall the app from the device
  3. Go to iTunes (or any equivalent software) and drag-drop the generated ipa file in the Apps tab on the left sidebar
  4. Still from iTunes, go to the device tab and drag-drop the app onto the device screen (or select it in the left column) and hit “Sync”

Now, it might look easy, but if you think about doing it tens of times in a day, I assure you, it’s a real pain in the butt. Not just for the amount of time wasted, but also for the amount of clicks, drags, drops etc. What if you could just run a script from the terminal and then sit and relax, while the script does all the “dirty” job for you? After some research, I found this fantastic blog post from Tom Krcha, talking about good practices to compile, install and profile your app for iOS. Thanks to the links contained in the post I have built a simple bash script that I thought could be worthwhile sharing.


echo “# Compiler: Packaging app, Sir.”;

case $1 in


/Applications/Adobe\ Flash\ Builder\ 4.6/sdks/4.6.0/bin/adt -package -target ipa-debug-interpreter -provisioning-profile PATH-TO-PROVISIONING-FILE -storetype pkcs12 -keystore PATH-TO-P12-CERTIFICATE – storepass “your-certificate-password” OUTPUT-IPA-PATH PATH-TO-XML-APP-DESCRIPTOR-FILE PATH-TO-SWF-FILE PATH-TO-OPTIONAL-ASSETS-FOLDER;

transporter_chief.rb OUTPUT-IPA-PATH;; #<— This will install your app on the device, so make sure it’s connected to your USB


/Applications/Adobe\ Flash\ Builder\ 4.6/sdks/4.6.0/bin/adt -package –target ipa-app-store -provisioning-profile PATH-TO-PROVISIONING-FILE -storetype pkcs12 -keystore PATH-TO-P12-CERTIFICATE -storepass “your-certificate-password” OUTPUT-IPA-PATH PATH-TO-XML-APP-DESCRIPTOR-FILE PATH-TO-SWF-FILE PATH-TO-OPTIONAL-ASSETS-FOLDER;

transporter_chief.rb OUTPUT-IPA-PATH;;


/Applications/Adobe\ Flash\ Builder\ 4.6/sdks/4.6.0/bin/adl -runtime /Applications/Adobe\ Flash\ Builder\ 4.6/sdks/4.6.0/runtimes/air/mac -profile mobileDevice -screensize 768×1004:768×1024 -XscreenDPI 132 -XversionPlatform IOS PATH-TO-XML-APP-DESCRIPTOR-FILE PATH-TO_OUTPUT-FOLDER;;


Let’s see what it does: As you can see it’s just a simple Switch/Case statement. You can provide an optional argument [test | release] to the script, and you can see it represents one of the cases in the main Switch:

  • If you pass “test” as an argument, the script will build your app using the quick method (note -target ipa-debug-interpreter) , the same you can select in the Flash Builder, which is fast but you know performances are ridiculous. Useful for quick tests.
  • If you pass “release”, the script will build using the slow method (note –target ipa-app-store), which is slow but performances are optimal.
  • If you don’t specify an argument, the switch will go through the default case “*)” and run you app in the desktop simulator (in this case simulating an iPad, as you can see from the argument -screensize 768×1004:768×1024)

The script makes use of the adt package command, whose documentation can be found here. It also uses transporter_chief.rb, a Ruby script that you can find here, to beam the compiled app to your device. Have a look at it and make it work as a first step. My script is just a simple idea to save time, you can build your own with some basic bash programming skills. Read the doc and create your own script to fit your needs, like different screenSize, or screenDPI, etc.. Hope you find it useful.