Page 1 of 1

Echoing Image using PHP problem

Posted: 2010-02-25T03:56:40-07:00
by barry100
Hi all. I am using the following to echo an image but i think it is not the best way

Code: Select all

 $resource = NewMagickWand();
   
MagickReadImage( $resource, $showpics ); 
		
	
$resource = MagickTransformImage( $resource, '0x0', '300x300' ); 
	$width = MagickGetImageWidth( $resource );
$height = MagickGetImageHeight( $resource ); 

$newheight = ($height/2/2);
$newwidth = ($width/2/2);
MagickCropImage( $resource, 150, 120, $newwidth, $newheight ); 

		 $src_file = 'imagesresized/'.$showpics;
MagickWriteImage($resource, $src_file);
		
				 
			         
					 
				echo'<img src="imagesresized/'.$showpics.'" />'; 
					 

The problem is that i dont know how to simply echo the image

I have used

header( 'Content-Type: image/jpeg' );
MagickEchoImageBlob( $resource );

But it dosnt seem to work. Btw just to let you know I am getting the images as part of a sequence of images, resizing them and then displaying them - I dont want a load of extra images made and saved on my server though so I just want something like

MagickEchoImageBlob( $resource );

and this to simply show the image. I dont want to use

header( 'Content-Type: image/jpeg' );

any help would be greaT!! ;)

Re: Echoing Image using PHP problem

Posted: 2010-03-03T22:11:49-07:00
by hankr
You are on the right track. Use readfile() to dump the written file directly to the browser:

Code: Select all

$src_file = 'imagesresized/'.$showpics;
MagickWriteImage($resource, $src_file);
header( 'Content-Type: image/jpeg' );
readfile( $src_file );
http://www.php.net/manual/en/function.readfile.php for details and an example