Page 1 of 1

[SOLVED] PHP generated image - output in the middle of HTML.

Posted: Wed Apr 13, 2005 6:17 am
by batfastad
Hi

I know PHP has many image processing functions and it looks like now I might look to use some of them.

The code below works and outputs the image, but how do I output the image into the middle of an HTML document?

I can output the image on a page on it's own...

Code: Select all

<?
$jpgFile = "http://www.domain.com/image.jpg";
$width = 100;

   // Get new dimensions
   list($width_orig, $height_orig) = getimagesize($jpgFile);
   $height = (int) (($width / $width_orig) * $height_orig);

   // Resample
   $image_p = imagecreatetruecolor($width, $height);
   $image = imagecreatefromjpeg($jpgFile);
   imagecopyresampled($image_p, $image, 0, 0, 0, 0, $width, $height, $width_orig, $height_orig);

header('Content-type: image/jpeg');
   // Output
   imagejpeg($image_p, "", 100);

?>
The above code resizes $jpgFile to $width in size.

I've tried adding HTML code above and below the PHP and removing the content-type header, but obviously the image just comes through in a text stream.

How do you get it to output the image in the middle of HTML and text?

Obviously I need to do some kind of

Code: Select all

echo("<img src=\"\">");
But what do I set src as?

Thanks

Ben

Posted: Wed Apr 13, 2005 6:22 am
by timvw
you need a script that generates and outputs an image....

you need a script that generates html, and that has an img tag in it, that links to the first script...


but you can't have both in the same....

Posted: Wed Apr 13, 2005 6:27 am
by batfastad
Ah right so in my main PHP page I go something like this...

Code: Select all

<img src=&quote;http://www.domain.com/imageresizer.php?image=224&quote; alt=&quote;&quote; border=&quote;0&quote; />
And the imageresizer script is the script I pasted in my previous message.

Annoyed I didn't think of that myself.
Thanks - I will try that!


Ben

Posted: Wed Apr 13, 2005 6:28 am
by batfastad
Problem solved - will mark post title as solved.

Thanks for your suggestion!!!


Ben