22

What are the differences between resizeImage and scaleImage?

I need to resize an image if its size is > $myLimit

Example (pseudocode):

$myLimit = 1MB
user uplaod an image of 1000x1000 of 2MB
2MB > $myLimit
while( $imagefilesize > $myLimit  ) {
  resizeImageBy 0.9%;
}

//> output 900x900 image of 900 kB

In the while block, which of the two methods should I use?

Edit: I found something that could help: http://www.imagemagick.org/Usage/resize/ But could someone simplify that?

caiosm1005
  • 1,686
  • 1
  • 19
  • 31
dynamic
  • 46,985
  • 55
  • 154
  • 231

3 Answers3

22

The difference between the two seems to be that scaleImage does a raw, pixel based resize, while resizeImage can use an interpolation filter:

imagick::INTERPOLATE_AVERAGE
imagick::INTERPOLATE_BICUBIC
imagick::INTERPOLATE_BILINEAR
...

that is likely to produce better results.

More on the various interpolation methods on Wikipedia.

Pekka
  • 442,112
  • 142
  • 972
  • 1,088
  • @yes I don't know, I don't know these filters in depth. I would try each one, and judge by the quality of the results – Pekka Mar 12 '11 at 21:07
  • 3
    @yes123: [Here](http://www.docstoc.com/docs/33154923/Filters-for-Common-Resampling-Tasks) you will find a paper saying that lanczos is indeed a good choice :). Just read the langzos section, it has the conclusion in there! [edit] Hmm the paper IS from 1990, might be fairly outdated. And come to think of it.. Since you are LOWERING the resolution, it doesn't need all that much. You might even use the BOX filter, just test a few images to be sure. – Yuri Mar 12 '11 at 21:11
  • @yes I don't know what problem you are trying to solve with the scaling - file size or resolution. I think you should ask a new question about that, and explain what your goal is – Pekka Mar 12 '11 at 21:11
1

Brilliant, their own documentation is awful... But ok: It looks to me like resizeImage is more powerful, and therefore the better choice... This link shows the usage along with some measurements for different filters.

Yuri
  • 2,008
  • 17
  • 36
  • ye .. the docu here lacks.. probabily is because GD are "built-in" and everyone use that (even tho they sux) – dynamic Mar 12 '11 at 21:09
0

According to my finding, when you want to scale down an image, use resizeImage. Because It gives you control over image quality and type of filter you want to use. But in the same case, scaleImage is also a good choice because when you have to scale down an image to let's say by factor of 10 and you are using resizeImage, then your resulting image will have many graphical errors.

In second case, when you have to scale up and image, then resizeImage will definetely have graphical error like while marks and lines and other stuff. In that case, scaleImage will come to rescue.

Uday Hiwarale
  • 233
  • 3
  • 15