0

I need to re-size image to any specific height and width value. But I'm not getting resized result. here is my code, please tell me either i'm doing something wrong or missing something.

IMOperation operationSmall = new IMOperation();
        operationSmall.addImage("conf/error.png");
        operationSmall.resize(300, 1000); // w*h
        operationSmall.addImage("conf/errir_small.png");

Original Image size: 1280x960 px. re-sized image size: 300x225

I tried to give different values, I'm only having issues in height. their doc is not complete and no code example I find on internet except that using scale (it skip filtering) may solve this problem. but how to use scale in code I have not idea.

Muneeb Nasir
  • 2,414
  • 4
  • 31
  • 54
  • 2
    I don't read or understand java much, but at the commandline you need an exclamation mark to disregard aspect ratio and force exact dimensions, like this `convert -resize 300x200! image...`. In the Java docs, there seems to be an option of adding a special 3rd parameter, so I guess you may need `operationSmall.resize(300,300,'!')` or something similar... or maybe Java uses double quotes for strings rather than the single quotes I suggested. – Mark Setchell Apr 29 '15 at 11:56
  • thank you it worked. if you add your comment in answer, I can +1 for you. :) – Muneeb Nasir Apr 29 '15 at 12:30

1 Answers1

1

I don't read or understand java much, but at the command-line you need an exclamation mark to force ImageMagick to disregard aspect ratio and resize to exact/specific dimensions, like this:

convert -resize 300x200! image.... 

In the Java docs, there seems to be an option of adding a special 3rd parameter, so I guess you may need

operationSmall.resize(300,1000,'!');

or something similar... or maybe Java uses double quotes rather than the single quotes I suggested.

Mark Setchell
  • 191,897
  • 31
  • 273
  • 432