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

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
User avatar
batfastad
Forum Contributor
Posts: 433
Joined: Tue Mar 30, 2004 4:24 am
Location: London, UK

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

Post 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
Last edited by batfastad on Wed Apr 13, 2005 6:29 am, edited 1 time in total.
timvw
DevNet Master
Posts: 4897
Joined: Mon Jan 19, 2004 11:11 pm
Location: Leuven, Belgium

Post 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....
User avatar
batfastad
Forum Contributor
Posts: 433
Joined: Tue Mar 30, 2004 4:24 am
Location: London, UK

Post 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
User avatar
batfastad
Forum Contributor
Posts: 433
Joined: Tue Mar 30, 2004 4:24 am
Location: London, UK

Post by batfastad »

Problem solved - will mark post title as solved.

Thanks for your suggestion!!!


Ben
Post Reply