Page 1 of 1

MagickWand returning garbage

Posted: 2008-08-15T09:25:25-07:00
by cczernia
I tried my first MagickWant script:

Code: Select all

$resource = NewMagickWand();

if (isset($resource)) {

	echo "ImageMagick is on";

	MagickReadImage( $resource, 'allia.jpg' );
	
	MagickResizeImage( $resource, 100, 100, MW_QuadraticFilter, 1.0 );
	
	header( 'Content-Type: image/gif' );
	MagickEchoImageBlob( $resource );
	}

else echo "no imagemagick"; 
and got this. Can someone tell me what I'm doing wrong. Thanks.

Image

Re: MagickWand returning garbage

Posted: 2008-08-15T09:44:05-07:00
by magick
You need to set the image format to GIF. By default, since the image is JPEG, MagickWand writes JPEG.

Re: MagickWand returning garbage

Posted: 2008-08-15T10:04:05-07:00
by cczernia
Thanks for the fast reply. First I tried changing Content-Type: image/gif to Content-Type: image/jpeg and that didn't help so I uploaded a gif and changed the code. I garbage changed but I still got garbage.

Code: Select all

$resource = NewMagickWand();
if (isset($resource)) {

	echo "ImageMagick is on";

	MagickReadImage( $resource, 'gb43j-mrd.gif' );
	
	MagickResizeImage( $resource, 100, 100, MW_QuadraticFilter, 1.0 );
	
	header( 'Content-Type: image/gif' );
	MagickEchoImageBlob( $resource );
	} 

Re: MagickWand returning garbage

Posted: 2008-08-15T11:13:07-07:00
by magick
Remove the echo statement so it does not mix with your image. You may also need to set a binary mode if you are running under Windows. We're using ImageMagick 6.4.2 and this command
  • php script.php > image.gif
    file image.gif
returns a proper GIF image as expected.