Using C++ on an ubuntu 10 machine, compiling with gcc.
I have a function that takes several different image formats stream and converts them to a PNG using GD.
The problem I'm having is when it comes across a corrupt image libpng and gd-png are outputting to std::cerr. Where i would just like them to return an error and move on.
Is there a #define or a parameter i can use to suppress this output?
Output: (there are at least 30 libpng warnings)
My code:libpng warning: Ignoring bad adaptive filter type
...
libpng warning: Ignoring bad adaptive filter type
gd-png: fatal libpng error: incorrect data check
gd-png error: setjmp returns error condition 2
Code:bool convertImageToPng(void *source, size_t sourceSize, std::string &dest, int& width, int& height, double cropLeft, double cropTop, double cropRight, double cropBottom) { bool retVal = false; gdImagePtr gdInput = NULL; const char* s = (const char*) source; if (sourceSize > 5 && (s[1] == 'P') && (s[2] == 'N') && (s[3] == 'G')) gdImagePtr gdInput = gdImageCreateFromPngPtr(sourceSize, source); else if (sourceSize > 5 && (s[0] == 'G') && (s[1] == 'I')) gdInput = gdImageCreateFromGifPtr(sourceSize, source); else if (sourceSize > 5 && (s[0] == (char)'\xFF') && (s[1] == (char)'\xD8')) gdInput = gdImageCreateFromJpegPtr(sourceSize, source); if (gdInput) { . . . } }




Reply With Quote
