问题
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:
The only problem I can see is with
imagejpeg()
's compression. Could I be right?Are there any libraries that provide the compression that I need?(retain pixel values that I changed)
回答1:
The JPEG file format is not very suitable for steganography if you do the steganography pixel by pixel.
JPEG uses an image compression - that even with maximum quality - that will destroy the information on the bit level on each pixel. The jpeg type of compression (lossy compression) is made for the human eye/brain to retain the image but not the bits of the image in the file .
You need to use an image format that is capable to retain the pixels - as you wrote it already as well. Such a format more likely is BMP with RLE compression or the TIFF image format with ZIP or RLE compression. That's called lossless data compression.
回答2:
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
回答3:
Use the imagepng()
instead of the imagejpeg()
function and set the compression to 0 :
bool imagepng ( resource $image [, string $filename [, int $quality [, int $filters ]]] )
See : http://php.net/manual/en/function.imagepng.php
来源:https://stackoverflow.com/questions/6561345/gd-imagejpeg-compression