Re: [GD-DEVEL] bug in gdImageGetPixel & JPEG Images? (OS X)
| From: | Pierre | Date: | Sun, 24 Jun 2007 21:56:17 +0000 |
| Subject: | Re: [GD-DEVEL] bug in gdImageGetPixel & JPEG Images? (OS X) | ||
| References: | 1 | Groups: | php.gd.devel |
| Request: | Send a blank email to php-gd-devel+get-209@lists.php.net to get a copy of this message | ||
Hi Ian,
On 6/24/07, Ian Banfield <ian.banfield@mail.mcgill.ca> wrote:
Hello!
I'm using OS X 10.4.10, xCode 2.5 (which uses gcc to compile C), GD
2.034 and libjpeg, installed via macports. (The same problems occures
if everything is compiled from sources, including 2.035 and the
latest CVS snapshot). The linker flags are set to "-lgd -lpng -lz -
ljpeg -lfreetype -lm", library search paths to /opt/local/lib and
header search paths to /opt/local/include (which should be the
appropriate settings for GD if it was installed via macports).
My code basically consists of the gdImageGetPixel example in the manual:
#include <stdio.h>
#include "gd.h"
int
main (void)
{
FILE *in;
gdImagePtr im;
int c;
in = fopen("image.jpg", "rb");
im = gdImageCreateFromJpeg(in);
fclose(in);
printf("%d by %d\n", gdImageSX(im), gdImageSY(im));
c = gdImageGetPixel(im, gdImageSX(im) / 2, gdImageSY(im) / 2);
printf("The value of the center pixel is %d; RGB values are %d,%d,%d
\n", c, im->red[c], im->green[c], im->blue[c]);
That's the problem. You are accessing the palette directly. It is not
recommended (and may not be supported in future version.
This works very well for gif files (replacing image.jpg by image.gif and ..createfromJpeg by ..fromGif)Loading a GIF image create a palette based image. The red/green/blue element are filled using the GIF palette. JPEG always creates a truecolor image. The palette elements are not used. I suggest to use the gdImageRed, gdImageGreen, gdImageBlue macros if you do not know if the image is true color or palette.
Any ideas?I hope it helps you to fix this problem :) Cheers, --Pierre