Advertisement
xeromino

resize

May 13th, 2016
249
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. PImage a, b, c;
  2.  
  3. void setup() {
  4.   size(642, 937);
  5.   PImage temp = createImage(width, height, RGB);
  6.   a = loadImage("a.jpg"); // reference image
  7.   b = loadImage("b.jpg");
  8.  
  9.   if (a.width<a.height) {
  10.     // reference image is portrait mode
  11.     float ratio = (float) a.height/b.height;
  12.     int w = int (b.width*ratio);
  13.     int h = int (b.height*ratio);
  14.     temp.copy(b, 0, 0, b.width, b.height, 0, 0, w, h);
  15.   } else {
  16.     // reference image is landscape mode
  17.     float ratio = (float) a.width/b.width;
  18.     int w = int (b.width*ratio);
  19.     int h = int (b.height*ratio);
  20.     temp.copy(b, 0, 0, b.width, b.height, 0, 0, w, h);
  21.   }
  22.   image(temp, 0, 0);
  23. }
  24.  
  25. void draw() {
  26. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement