MagickWand returning garbage

MagickWand for PHP is an object-oriented PHP interface to ImageMagick. Use this forum to discuss, make suggestions about, or report bugs concerning MagickWand for PHP.
Post Reply
cczernia

MagickWand returning garbage

Post by cczernia » 2008-08-15T09:25:25-07:00

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

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

Re: MagickWand returning garbage

Post by magick » 2008-08-15T09:44:05-07:00

You need to set the image format to GIF. By default, since the image is JPEG, MagickWand writes JPEG.

cczernia

Re: MagickWand returning garbage

Post by cczernia » 2008-08-15T10:04:05-07:00

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 );
	} 

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

Re: MagickWand returning garbage

Post by magick » 2008-08-15T11:13:07-07:00

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.

Post Reply