0

I am trying to use libvips writeToBuffer method with quality, but it's not apply the quality to the image is there any other method for set the quality. I have below case if file exists then it call the writeToFile otherwise writeToBuffer. IS there any solution for achieve below case?

$image = Vips\Image::newFromFile($sourceimgfile);
$result = $image->writeToBuffer('.jpg', ['Q' => 50]);
file_put_contents($destinationimgfile, $result);

Actual output:

enter image description here

If I set image quality 50, then it should give me low resolution image but still it generate same image like input image. It didn't applied the quality on image.

halfer
  • 19,824
  • 17
  • 99
  • 186
Test Human
  • 31
  • 1
  • 7
  • It should work. You need to give more information: what file sizes do you see, what do you expect, what libvips version are you using, what platform are you using, make a complete, runnable program that shows the problem, etc. etc. – jcupitt Dec 25 '20 at 10:24
  • I updated my question with proper inputs – Test Human Dec 25 '20 at 10:49
  • It's Working actually it i tried to apply low resolution, i compare both images it works fine. Thank you – Test Human Dec 25 '20 at 10:59

1 Answers1

0

It should work. You can test this at the command-line like this:

$ vips jpegsave_buffer astronauts.png --Q 20
VIPS_TYPE_BLOB, data = 0x7f5388000b60, length = 55617
$ vips jpegsave_buffer astronauts.png --Q 90
VIPS_TYPE_BLOB, data = 0x7fefbc6f9010, length = 263341

So at Q 20, it's only 55kb, but Q 90 is 260kb.

jcupitt
  • 10,213
  • 2
  • 23
  • 39