MagickReadImageBlob failure with .ico files

Post any defects you find in the released or beta versions of the ImageMagick software here. Include the ImageMagick version, OS, and any command-line required to reproduce the problem. Got a patch for a bug? Post it here.
Post Reply
smugsotemp

MagickReadImageBlob failure with .ico files

Post by smugsotemp »

I'm using PHP 5.2.0 with ImageMagick-6.3.2-3-Q8 for windows.

I've noticed a problem with MagickReadImageBlob().

The following code works fine:
$image = file_get_contents("c:\image.gif");
print_r($image);
$resource = NewMagickWand();
MagickReadImageBlob($resource,$image);


While the following code crashes with "Fatal error: magickreadimageblob(): An unknown C API exception occurred [on C source line 7670] in ..."

$image = file_get_contents("c:\image.ico");
print_r($image);
$resource = NewMagickWand();
MagickReadImageBlob($resource,$image);


I've tried it with several .ico files and all produce the same result.
User avatar
magick
Site Admin
Posts: 11064
Joined: 2003-05-31T11:32:55-07:00

Re: MagickReadImageBlob failure with .ico files

Post by magick »

Add
  • MagickSetFilename($resource,"ico:favicon.ico");

just before the MagickReadImageBlob() statement. This ico: assists ImageMagick in determining your image is in the ICO image format.
smugsotemp

Re: MagickReadImageBlob failure with .ico files

Post by smugsotemp »

Hey, magick.
I did what you suggested and it removed the error in MagickReadImageBlob.
However, I still cannot get a php buffer of the image.

Once I do the following:

Code: Select all

$image = file_get_contents("c:\image.ico");
$resource = NewMagickWand();
MagickSetFormat($resource,"ico");
MagickSetFilename($resource,"ico:favicon.ico");
MagickReadImageBlob($resource,$image);
$newIcoImage = MagickGetImagesBlob($resource);
I get nothing in $newIcoImage (not false, just empty). If I try to write it to a file (using fwrite) I get a file with size of 0.

Thanks,
User avatar
magick
Site Admin
Posts: 11064
Joined: 2003-05-31T11:32:55-07:00

Re: MagickReadImageBlob failure with .ico files

Post by magick »

You found a bug. The blob is not created if it begins with a NULL character. You can write to other formats other than ICO such as MIFF or you can dowload the patch at ftp://ftp.imagemagick.org/pub/php/betasometime tommorrow. Thanks for the problem report.
magickchina

Re: MagickReadImageBlob failure with .ico files

Post by magickchina »

magick wrote:You found a bug. The blob is not created if it begins with a NULL character. You can write to other formats other than ICO such as MIFF or you can dowload the patch at ftp://ftp.imagemagick.org/pub/php/betasometime tommorrow. Thanks for the problem report.
The bug is still exists, I met it , with the latest version of imageMagick AND MagickWand

My env:
winxp + ImageMagick-6.3.6-Q16 + MagicWand 1.0.5 + PHP5.2.4

My test code

Code: Select all

$image = file_get_contents("c:\favicon.ico");
$resource = NewMagickWand();
MagickSetFormat($resource,"ico");
MagickSetFilename($resource,"ico:favicon.ico");
MagickReadImageBlob($resource,$image);
$newIcoImage = MagickGetImagesBlob($resource);
echo $newIcoImage;
die;
it output nothing
User avatar
magick
Site Admin
Posts: 11064
Joined: 2003-05-31T11:32:55-07:00

Re: MagickReadImageBlob failure with .ico files

Post by magick »

We tried your script with ImageMagick 6.3.6-2 and MagickWand 1.0.5 and it output an ICO image as expected. Not sure why it failed for you.
magickchina

Re: MagickReadImageBlob failure with .ico files

Post by magickchina »

magick wrote:We tried your script with ImageMagick 6.3.6-2 and MagickWand 1.0.5 and it output an ICO image as expected. Not sure why it failed for you.
Are you test it in windows xp ?
My php version: 5.2.4

I download php-5.2.4_magickwand_q16_st.dll from here.

http://www.dirk.sh/dirk/magickwand/
aireys

Re: MagickReadImageBlob failure with .ico files

Post by aireys »

I have the same problem.
I work with C API.
My code:

FILE *f = fopen("bomb.jpg", "rb");
size_t fsize = getfilesize(f);
void *content = malloc(fsize);
read(content, 1, fsize, f);

//I'm sure above is ok

MagicKWand *wand = NewMagickWand();
MagickSetFormat(wand, "jpg");
MagickSetFilename(wand, "jpg:out.jpg");
status = MagickReadImageBlob(wand, content, fsize);

status is MagickFalse
why ?please help me. My email: aireys@126.com
Post Reply