2

I am using both PHP imagick and PHP vips library for image operations. I am working on image resize operation. For imagick I am using resizeImage() function and for vips I am using resize() function. But the output of both the image are different for same height and width. I want to same output for vips. Here I add my code which I am using for vips. I want same result for vips also, which I got into imagick

<!-- Imagick Code -->
$img = new Imagick($ipFile); 
$img->resizeImage(1000, 1000, Imagick::FILTER_LANCZOS, 1, true);
$img->writeimage($opFile);

<!-- VIPS Code -->
$im = Vips\Image::newFromFile($ipFile);
$im = $im->resize($ratio, ['kernel' => 'lanczos2']);
$im->writeToFile($opFile);

Vips Output file:
Vips Output file Imagick Output file:
Imagick Output file

1 Answer 1

3

Don't use resize with php-vips unless you really have to. You'll get better quality, better speed and lower memory use with thumbnail.

The thumbnail operation combines load and resize in one, so it can exploit tricks like shrink-on-load. It knows about transparency, so it'll resize PNGs correctly. It also knows about vector formats like PDF and SVG and will size them in the best way.

Try:

<!-- VIPS Code -->
$im = Vips\Image::thumbnail($ipFile, 1000);
$im->writeToFile($opFile);

Benchmark:

$ /usr/bin/time -f %M:%e convert ~/pics/nina.jpg -resize 1000x1000 x.jpg
238836:0.77
$ /usr/bin/time -f %M:%e vips resize ~/pics/nina.jpg x.jpg .1653439153
60996:0.39
$ /usr/bin/time -f %M:%e vips thumbnail ~/pics/nina.jpg x.jpg 1000
49148:0.16

nina.jpg is a 6k x 4k RGB JPG image.

  • imagick resizes in 770ms and 240MB of memory
  • vips resize takes 390ms and 61MB of memory
  • vips thumbnail takes 160ms and 50MB of memory

Quality will be the same in this case.

9
  • Thanks for the help. Need one more help imagick provide Imagick::FILTER_LANCZOS for apply filter and also there is one blur option in resize option how can i achieve that using vips?
    – Amv
    Aug 31, 2020 at 13:30
  • 1
    libvips thumbnail uses lanczos3.
    – jcupitt
    Aug 31, 2020 at 13:40
  • Is there any way for change lanczos3?
    – Amv
    Aug 31, 2020 at 14:01
  • 1
    thumbnail is supposed to implement best practice, so there are very few options. Why do you need a different kernel?
    – jcupitt
    Aug 31, 2020 at 14:23
  • Little bit confused about filters now got the idea and i don't need to change kernel. Thank you for the help
    – Amv
    Aug 31, 2020 at 14:36

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.