GD imagejpeg() compression?

itsachen picture itsachen · Jul 3, 2011 · Viewed 9.8k times · Source

I'm working on a project where I edit the pixels of a jpg in PHP using the GD library. Its very crucial and key to my project that the output from PHP retains the pixel values I set (cough-steganography-cough).

This is the first time I've attempted image manipulation in PHP. I've had no problems before in my Java implementations, so I was foolish not to investigate GD's jpeg compression quality before pursuing further.

It turns out that after all my effort, my code does not function the way its supposed to. I am pretty sure it is not my code (tested the encode and decode functions on edited image resources and they worked).

My questions are:

  1. The only problem I can see is with imagejpeg()'s compression. Could I be right?

  2. Are there any libraries that provide the compression that I need?(retain pixel values that I changed)

Answer

Balanivash picture Balanivash · Jul 3, 2011

By default the quality of the image output from imagejpeg is 75, Try setting it at 100 to get the image at full quality.

  bool imagejpeg ( resource $image [, string $filename [, int $quality ]] )

Check the manual for further details.

Also try using imagecopyresampled. (I think you would have been using imagecopyresized somewhere in your code. Use imagecopyresampled instead of it. )

EDIT

Then I think you should try ImageMagick(or GD2). It gives a better quality than GD . Check this