[Php] Image return /print

beandab

New Member
Messages
18
Reaction score
0
Points
0
Hey all,
well i am also a newbie :)

i saw this on many sites:
<img src="somephp.php?blabla" width="100">

how can i make that to?

i want to reffer to a php file that returns or prints a jpg image and in the
<img src=must be a php url>

Best regards M
 

woiwky

New Member
Messages
390
Reaction score
0
Points
0
You need to use the gd library image functions to accomplish that. You also have to be sure to specify the content-type header before outputting the image data.

Here's an example from php.net:

PHP:
<?php
header ("Content-type: image/png");
$im = @imagecreatetruecolor(120, 20)
      or die("Cannot Initialize new GD image stream");
$text_color = imagecolorallocate($im, 233, 14, 91);
imagestring($im, 1, 5, 5,  "A Simple Text String", $text_color);
imagepng($im);
imagedestroy($im);
?>

This code will generate a 120x20 image with a black background with the text "A Simple Text String" in red, output it in png format, and then free the memory associated with that image.
 

oscetips

New Member
Messages
26
Reaction score
0
Points
0
adapted from php.net...

-- image.php --
<?php
$filename = "path/to/image/".$_GET['name'].".jpg";
header('Content-type: image/jpeg');
header('Content-transfer-encoding: binary');
header('Content-length: '.filesize($filename));
readfile($filename);
?>

--your html code--
<img src="http://forums.x10hosting.com/programming-help/image.php?name=test">
 
Top