Skip to content

Instantly share code, notes, and snippets.

@falkolab
Created January 28, 2016 14:57
Show Gist options
  • Save falkolab/00a265ae9d0bab2e6c89 to your computer and use it in GitHub Desktop.
Save falkolab/00a265ae9d0bab2e6c89 to your computer and use it in GitHub Desktop.

Revisions

  1. falkolab created this gist Jan 28, 2016.
    15 changes: 15 additions & 0 deletions resizeToContainer.js
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,15 @@

    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;
    }