MagickEchoImageBlob() display junk character on screen

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
snowbydave1

MagickEchoImageBlob() display junk character on screen

Post by snowbydave1 » 2007-03-09T06:57:02-07:00

Please anybody guide me, I am using following code for display image on screen

header('Content-Type: image/jpeg');
$magick_wand = NewMagickWand();

if (MagickReadImage($magick_wand, "paste_img/20070309130202.jpg") != 0)
{
MagickSetFormat($magick_wand, 'jpeg');
MagickEchoImageBlob($magick_wand);
}
else
{
echo MagickGetExceptionString($magick_wand);
}

DestroymagickWand($magick_wand);


But it will display junk character on screen.

Snowby Dave

boon4376

Re: MagickEchoImageBlob() display junk character on screen

Post by boon4376 » 2009-05-05T16:30:00-07:00

I am also having this problem. I have recently installed ImageMagick and Magickwand on ubuntu for use with PHP.

I am able to load an image, rotate it, takes its width and height, however whenever i try and use

MagickEchoImageBlob i get a bunch of random characters and junk where the image should be. Tried with a .jpg and a .png image.

Code: Select all



<?php

echo <<<html
Test image rotate: <br><br>
html;

$resource = NewMagickWand();
MagickReadImage( $resource, 'images/image_1.jpg' );

$w = MagickGetImageWidth($resource); 
$h = MagickGetImageHeight($resource);

echo "image height & width: $h , $w <br>";

//=========================================>
// Rotate the image and see if the width
// and height change properly
//=========================================>
echo "Rotating image.... <Br>";

MagickRotateImage($resource, null, 90);

$w = MagickGetImageWidth($resource); 
$h = MagickGetImageHeight($resource);
echo "rotated image height & width: $h , $w <br>";

echo "Image: <Br>";
MagickEchoImageBlob($resource);
?>



boon4376

Re: MagickEchoImageBlob() display junk character on screen

Post by boon4376 » 2009-05-05T16:45:11-07:00

You know what, in my case it doesnt matter anymore. I have found an easy way around it.

I'm just saving the image now and displaying it the way i normally would with HTML.

Heres the code of loading an image, rotating it, saving it, and then displaying it.
Each time the page refreshes, the image rotates.

Code: Select all

<?php

echo <<<html
Test image rotate: <br><br>
html;

$resource = NewMagickWand();
$imagePath = "images/image_1.jpg";
MagickReadImage( $resource, $imagePath );

$w = MagickGetImageWidth($resource); 
$h = MagickGetImageHeight($resource);

echo "image height & width: $h , $w <br>";

//=========================================>
// Rotate the image and see if the width
// and height change properly
//=========================================>
echo "Rotating image.... <Br>";

MagickRotateImage($resource, null, 90);

$w = MagickGetImageWidth($resource); 
$h = MagickGetImageHeight($resource);
echo "rotated image height & width: $h , $w <br>";

//============================================>
// Save the image to the original image path
// specified at the beginning "$imagePath"
// over writing the original image
//============================================>
echo "Saving Rotated Image... <br>";
MagickWriteImage($resource, $imagePath);

//===============================>
// Display the image
//===============================>
echo <<<image
<img src="$imagePath">
image;
?>

Post Reply