On Android, EXIF orientation information is not taken into account when an image is resized or cropped using e.g. Ti.Blob.imageAsThumbnail()
. Because of this bug, pictures appear rotated after resizing them.
There has been a ticket for this since June last year, but still no fix. Stefan Moonen soon decided he couldn’t wait no longer and created the fh.imagefactory module.
Here’s a simple CommonJS module to workaround the issue:
var ImageFactory = require('fh.imagefactory'); exports.imageAsThumbnail = function(size, quality) { if (Ti.Platform.name === 'android') { ImageFactory.rotateResizeImage(image.nativePath, size, quality || 100); return image; } else { return image.imageAsThumbnail(size); } };
Comments
Kristján Mikaelsson
Thanks, saved my life!
Ricardo Alcocer
This module is actually a great example of how easy it is to create a native Android module for Titanium. https://github.com/freshheads/fh.imagefactory/blob/master/android/src/fh/imagefactory/ImagefactoryModule.java
Brad White
Am I imagining things, or is there an “image” parameter missing from the function in the CommonJS module outlined above?
Dragos Stancu
You’re right, sir.
Thanks Freshheads for the module, saving my life as we speak.
Ryan G
Very helpful, thanks Fokke and Moonen!
vitory
U can download app library for developer
https://play.google.com/store/apps/details?id=com.libraries.developers
i see it has sourcecode vary lib ulits for android and it reslove problem of U
U use lib universal-image-loader resize image, problem is ok
nav
Simply clicked a photo and applied its blog and the image got rotated(TiSDK 3.5.1). Tried using this module and it does not help.