Skip to content

Instantly share code, notes, and snippets.

@falkolab
Created January 28, 2016 14:57
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save falkolab/00a265ae9d0bab2e6c89 to your computer and use it in GitHub Desktop.
Save falkolab/00a265ae9d0bab2e6c89 to your computer and use it in GitHub Desktop.
Titanium SDK helper to resize
function resizePhoto(blob, size) {
var measurement = require('alloy/measurement'), w, h;
if (blob.width / blob.height >= size.width / size.height) {
w = measurement.dpToPX(size.width);
h = blob.height * measurement.dpToPX(size.width) / blob.width;
} else {
w = blob.width * measurement.dpToPX(size.height) / blob.height;
h = measurement.dpToPX(size.height);
}
result = blob.imageAsResized(w, h);
return result;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment