Page 208 - Open Soource Technologies 304.indd
P. 208
Unit 12: Images
• ImageFilledArc() — To fill a partial ellipse. Notes
• ImageFilledPlygon() — To fill a polygon.
• ImageFilledRectangle() — To fill a rectangle.
These functions are used just like nonfill drawing functions explained above.
1. Image Filled Rectangle ($image One, 10, 20, 40, 70, $green);
PHP comes with several built-in styles that are used in the display. For example IMG_ARC_PIE
says to create a rounded edge.
12.4 Modifying an Existing Image
In most cases, creating an image from scratch is overkill. For most web purposes, you can usually
design the basic background of your image using a normal image editor like Photoshop and
only add any additional text or graphical elements that need to be dynamically drawn using
PHP. This allows you to speed up your scripts and reduce the resource consumption on your
web server. It also lets you create your picture using professional picture designing tools.
To use an existing GIF, JPEG or PNG image as a canvas on which you add additional elements,
use one of the following functions instead of imagecreate().
imagecreatefromgif ( string $filename )
imagecreatefromjpeg ( string $filename )
imagecreatefrompng ( string $filename )
For example, if you created a GIF file called “mytemplate.gif”, the function can be called as
follows:
$myimage = imagecreatefromgif ( “mytemplate.gif” );
Like the basic imagecreate() function, these functions return FALSE if they fail to load the image
for any reason.
12.4.1 Using True Type Fonts
If you want to use a True Type font, you will need to use imagettftext() instead. For details on
how to use this function, please consult the function’s manual page on php.net.
You should note a few things, though, before using this function:
• Check that your web host has compiled FreeType support into PHP before you rely on
this function.
• Find out whether your web host’s PHP is using GD version 1 or 2. This affects a number
of things, including the meaning of the font size parameter to the function (whether it
means pixel size or point size).
• Note that the coordinates for the text has a different starting point from imagestring().
That is, a coordinate like (say) 10, 20 has a different meaning in the two functions.
• Make sure the font you want exists on your web server. Remember that your web server
is not the same as your computer. Just because a font like Arial exists on your computer
LOVELY PROFESSIONAL UNIVERSITY 203