GD imagejpeg() compression?

2019-05-05 08:49发布

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)

3条回答
走好不送
2楼-- · 2019-05-05 09:20

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楼-- · 2019-05-05 09:33

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.

查看更多
We Are One
4楼-- · 2019-05-05 09:45

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

查看更多
登录 后发表回答