4

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)

Balanivash
  • 6,709
  • 9
  • 32
  • 48
itsachen
  • 199
  • 1
  • 3
  • 10

3 Answers3

3

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

Balanivash
  • 6,709
  • 9
  • 32
  • 48
  • Ah I forgot to mention I did set the quality to 100, no luck there. Also I don't use imagecopyresized in my code :/ – itsachen Jul 03 '11 at 06:09
  • Ah. Unfortunately I think I'm using GD2. I'll give ImageMagick a shot but my current web host doesn't support it/allow me to install. -sigh- Yet another problem added to my plate – itsachen Jul 03 '11 at 06:35
  • Think this is all that PHP could offer you. :) – Balanivash Jul 03 '11 at 06:38
2

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.

hakre
  • 193,403
  • 52
  • 435
  • 836
  • I think I'll try PNG or GIF, both supported by GD. Thanks for the info. Will post results later! – itsachen Jul 03 '11 at 18:42
  • ...And PNG works great! Thanks for the heads up on compression types vs. file types, I neglected to take that into account. – itsachen Jul 03 '11 at 19:30
0

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

Guillaume Chevalier
  • 9,613
  • 8
  • 51
  • 79