Problem using gdImageGetPixel()

[email protected] (Yorn) Thu, 18 Dec 2008 10:41:29 +0100
Newsgroups php.gd.devel
Organization streamnik
Message-ID <[email protected]>
Hi,

I was just making a code conversion (C) from gd to gd2 in my project and got 
to the problem that gdImageGetPixel() does not return any reasonable values. 
With libgd-1.8.4 everything is fine but neither 2.0.34 (within ubuntu 7.10) 
nor 2.0.35 (compiled natively) will do the job.

I tried the example code from the web-page, which also does not work:

----------- snipp ------------
#include <stdio.h>
#include <gd.h>

int main()
{
    FILE *in;
    gdImagePtr im;
    int c;
    in = fopen("pic1.jpg", "rb");
    im = gdImageCreateFromJpeg(in);
    fclose(in);
    c = gdImageGetPixel(im, gdImageSX(im) / 2, gdImageSY(im) / 2);
    printf("The value of the center pixel is %d", c);
//    int red = im->red[c];
//    int green = im->green[c];
//    int blue = im->blue[c];

//    printf(" RGB values are %d %d %d\n", red, green, blue);
    gdImageDestroy(im);
    return(0);
}

---------- snipp ------------

when I comment in the rest, the program stops with a segfault, as variable c 
is completely nonsense.

Anybody else with that problem? Or any idea?

- Yorn