Skip to content

Instantly share code, notes, and snippets.

@brentonhouse
Forked from falkolab/resizeToContainer.js
Created March 14, 2017 22:52
Show Gist options
  • Select an option

  • Save brentonhouse/0b041daba5c448ea763c39481ee7966c to your computer and use it in GitHub Desktop.

Select an option

Save brentonhouse/0b041daba5c448ea763c39481ee7966c 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