Page 210 - Open Soource Technologies 304.indd
P. 210
Unit 12: Images
</body> Notes
</html>
The following ‘myscript2.php’ file creates an image BUT I can’t get that image to load using
the img tag:
HTML Code:
<img src=”myscript2.php”/>
PHP Code:
<?php
// Path to our font file
$font = ‘arial.ttf’;
$fontsize = 10;
$quotes = $_GET[‘cmment’];
// get the quote and word wrap it
$quote = wordwrap($quotes,20,”<br />\n”);
// Create image
$image = imagecreatefrompng(‘baseimage.png’);
// pick color for the background
$bgcolor = imagecolorallocate($image, 100, 100, 100);
// pick color for the text
$fontcolor = imagecolorallocate($image, 255, 255, 255);
// fill in the background with the background color
imagefilledrectangle($image, 200, 100, 400, 200, $bgcolor);
// x,y coords for imagettftext defines the baseline of the text: the
lower-left corner
// so the x coord can stay as 0 but you have to add the font size
to the y to simulate
// top left boundary so we can write the text within the boundary
of the image
$x = 0;
$y = $fontsize;
imagettftext($image, $fontsize, 0, $x, $y, $fontcolor, $font,
$quote);
// tell the browser that the content is an image
header(‘Content-type: image/png’);
// output image to the browser
imagepng($image);
// delete the image resource
imagedestroy($image);
?>
Enterprise Solutions Using Java-PHP
Summary: Production use of Resin® and Quercus™ to deploy combined Java-PHP solution
for Emergency Preparedness and Response for Healthcare.
Solution: Combined Java-PHP architecture. Contd...
LOVELY PROFESSIONAL UNIVERSITY 205