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.
Recently I’ve been working a lot on iPad using Adobe AIR, which is really good to quickly create iOS applications, but of course it has it’s limitations.
One of these is that when you shoot a picture using CameraUI, and you rotate your iDevice, your image comes out rotated.
How can you find out the device orientation in order to adjust the picture rotation?
The answer resides in the EXIF metadata! Actually, EXIF data contains a whole bunch of hidden information about your file, including an “Orientation” tag that can have 5 different values:
- 1 – LANDSCAPE
- 3 – LANDSCAPE_REVERSE
- 6 – PORTRAIT
- 8 – PORTRAIT_REVERSE
- 9 – UNKNOWN
So, once you have this value, you just need to rotate your Bitmap, or BitmapData, or whatever you have, according to this value and to the current device orientation. I want to use my situation as an example:
- You have an iPad application running in Landscape mode.
- Your application launches CameraUI to take a photo.
- You rotate your iPad in LANDSCAPE mode and shoot the photo.
- Your app closes the CameraUI and goes back to Landscape mode.
In this case, the picture you have just taken will appear rotated by 90 degrees!
So, how do you get the orientation value???
Thanks to this fantastic post by Christian Cantrell I found out… [to-be-continued]