Archive for July, 2007

2. The name of the second, or source (Jetty web server)

Thursday, July 26th, 2007

2. The name of the second, or source image ($image2 in this example) 3. The x coordinate of the destination image (0 in this example, representing the leftmost boundary) 4. The y coordinate of the destination image (0 in this example, representing the upper boundary) 5. The x coordinate of the second image (0 in this example) 6. The y coordinate of the second image (0 in this example) 7. The width of the portion of the second image to be merged ($width in this example, representing as much of the second image that will fit on the destination image) 8. The height of the portion of the second image to be merged ($height in this example, representing as much of the second image that will fit on the destination image) 9. The percent of transparency of the two images to be merged, with 100 being equal to the second image completely overwriting the first (15 in this example) Let s talk briefly about numbers seven and eight. Because imagecopymerge() can merge only a portion of one image with another, you have to specify how much of the image you want merged. The CBA logo is huge, and bigger than the user s photo. You only wanted to merge the portion as big as your user s photo, which is why you used $width and $height. If your logo is tiny, you would specify its width and height, assuming you want to merge the whole thing with your first image. We hope you re still with us because there is one more thing we would like to do. Creating Thumbnails Of course, showing your users images at full size is fine if they want to see them up close. However, it s not too conducive for showing a photo gallery or list of many photos on a page. This section discusses discuss how you can automatically create a thumbnail of each of your uploaded files that will be used for just that purpose a photo gallery of all your photos. Try It Out Creating Thumbnails You want to automatically create a thumbnail version of all the images that are uploaded by the users, so you will be modifying check_image.php and including this function. 1. Create a subdirectory of your images folder to house the thumbnails. For this example, we created c:Program FilesApache GroupApache2imagesthumbs. Make sure your directory has write permissions. 2. Modify your check_image.php file as follows (changes are highlighted): Please visit Domain Name Hosting services for high quality webhost to host and run your jsp applications.

3. Okay, now (Best web design) do as you re told. Try

Thursday, July 26th, 2007

3. Okay, now do as you re told. Try it out, already! Although you don t have the logo.gif file, use any file you like just make sure your script can find it. Your screen should look something remotely resembling that in Figure 7-7. Figure 7-7 How It Works You have simply added another option for your users; and you did it using the imagecopymerge() function in modifyimage.php. Note that before you could merge the two images, you had to make the second image GD friendly by creating a duplicate copy. Because your image was a GIF image, you used the imagecreatefromgif function. Look at this line from that script: imagecopymerge($image, $image2, 0,0,0, 0, $width, $height, 15); The parameters for the imagecopymerge function are as follows, in this order: 1. The name of the destination image ($image in this example, since the $image file is the one you are making all the changes to, and the one that will be shown at the end of your script) 219 Manipulating and Creating Images with PHP
You need excellent and relaible webhost company to host your web applications? Then pay a visit to Inexpensive Web Hosting services.

3. The rotation of the text (0 in (Geocities web hosting)

Wednesday, July 25th, 2007

3. The rotation of the text (0 in this example) 4. The x coordinate for the starting position of the text, with 0 being the leftmost boundary of the image (20 in this example) 5. The y coordinate for the starting position of the text, with 0 being the upper boundary of the image (20 in this example) 6. The color of the text using the color index (0, or black, in this example) 7. The name of the font file you want to reference, to be located automatically in the default font directory (arial.ttf in this example) 8. The string of text to be shown (contents of the $image_caption variable in this example) Again, feel free to experiment with different fonts, colors, and locations for your text this is only one small example. In the course of your experimentation, be sure you fill in values for each one of the eight parameters, or you will get an error message. Adding Watermarks and Merging Images Because you are showing these images on the Movie Review Site, make your logo show up lightly behind each image that is hosted by you, as a sort of watermark. You can do this with your own logo to protect any copyrighted images, as we did easily enough with the text. In this section, you will actually be merging two images (your source image and your logo image) to create the desired effect. Let s make the changes. Try it Out Merging Two Images To merge the two images, you will again need to change your showimage.php file and your modify image.php file. 1. Add the following line to your showimage.php file, in the same section as before: include Movie Review Site watermark
2. Add the following line to your modifyimage.php file, as before: //**INSERT NEAR THE TOP OF THE FILE if (isset($_POST[ watermark ])) { $watermark = $_POST[ watermark ]; } else { $watermark = ; } Then add the following lines later on in the script: if ($watermark == on ) { $image2 = imagecreatefromgif( images/logo.gif ); imagecopymerge($image, $image2, 0,0,0, 0, $width, $height, 15); } 218 Chapter 7
Go visit our java server pages services for a reliable, lowcost webhost to satisfy all your needs.

Figure 7-6 (Web hosting services) How It Works First, you add

Wednesday, July 25th, 2007

Figure 7-6 How It Works First, you add the embed caption option to your form in showimage.php. This is a no-brainer, right? Good. Then you add the imagettftext() function to your modifyimage.php file like this: //**INSERT THE FOLLOWING LINES: if ($text == on ) { imagettftext($image, 12, 0, 20, 20, 0, arial.ttf , $image_caption); } //**END OF INSERT The imagettftext() function is only one of the many text/string functions available in PHP/GD. The function is made up of eight values, in this order: 1. The image where the text is to go ($image in this example) 2. The font size of the text (12 in this example) 217 Manipulating and Creating Images with PHP
From our experience, we can recommend PHP Web Hosting services, if you need affordable webhost to host and run your web application.

} $action = $_POST[ action ]; //**INSERT (Web server iis) THE FOLLOWING LINES:

Tuesday, July 24th, 2007

} $action = $_POST[ action ]; //**INSERT THE FOLLOWING LINES: if (isset($_POST[ text ])) { $text = $_POST[ text ]; } else { $text = ; } //**END OF INSERT //get info on the pic we want $getpic = mysql_query( SELECT * FROM images WHERE image_id = $id ) or die(mysql_error()); $rows = mysql_fetch_array($getpic); extract($rows); $image_filename = images/ . $image_id . .jpg ; list($width, $height, $type, $attr) = getimagesize($image_filename); $image = imagecreatefromjpeg( $image_filename ); if ($bw == on ) { imagefilter($image, IMG_FILTER_GRAYSCALE); } //**INSERT THE FOLLOWING LINES: if ($text == on ) { imagettftext($image, 12, 0, 20, 20, 0, arial.ttf , $image_caption); } //**END OF INSERT if ($action == preview ) { header( Content-type:image/jpeg ); imagejpeg($image); } if ($action == save ) { imagejpeg($image, $image_filename); $url = location:showimage.php?id= . $id . &mode=change ; header($url); } ?> 3. Now go back to http://localhost/showimage.php?id=1 and try previewing your image with the embed caption feature checked. You should see something similar to Figure 7-6. You can see how easy it is to automatically add copyright notices or any text at all to your images. Let s break it down. 216 Chapter 7
Check Tomcat Web Hosting services for best quality webspace to host your web application.

Freelance web design - Try It Out Embedding Text in Images You

Tuesday, July 24th, 2007

Try It Out Embedding Text in Images You will be modifying your showimage.php and modifyimage.php files to show captions along with the images, but they will be minor changes. 1. Locate the following section in your showimage.php file, and add the highlighted lines:


Modifying Your Image

Please choose if you would like to modify your image with any of the following options. If you would like to preview the image before saving, you will need to hit your browser s back button to return to this page. Saving an image with any of the modifications listed below cannot be undone.

> black & white
embedded caption

2. The arial.ttf font is used in this exercise, but you should use a font that is installed on your server. If you attempt to run the following script with a font that is not installed on the server, you will get an error. Now that that s cleared up, add the following highlighted lines to your modifyimage.php file: From our experience, we can recommend PHP Web Hosting services, if you need affordable webhost to host and run your web application.

Managed web hosting - Next you decide whether or not you want

Monday, July 23rd, 2007

Next you decide whether or not you want to keep the changes you are making, and you do so in the following lines: if ($action == preview ) { header( Content-type:image/jpeg ); imagejpeg($image); } If you are only previewing the image, you will spit it directly out to the browser (which is done using the imagejpeg() function and without a specific filename for the destination). But why did you send a header to the browser, and why is there no HTML? Again, because you are spitting out the image directly, you don t need (and actually can t send) any text along with the image. You are only sending the image itself. If you don t specify what content type is in your page, the browser will assume it is text and you will get a page full of garbage. Don t believe us? Go ahead and comment out the header line and reload the page. See what we mean? You send the header so the browser will interpret the image stream correctly. Because the browser is expecting an image, if you try to send any text along with the image, after the header has been sent, you will see a big ol error. If your users want to save the changes to the image, and they click save when submitting, you process the following lines of code: if ($action == save ) { imagejpeg($image, $image_filename); $url = location:showimage.php?id= . $id . &mode=change ; header($url); } Notice the use of the mode variable (so your users will see the confirmation text when the page loads) and the filename specified in the imagejpeg() function. Specifying a destination filename saves the temporary image to a permanent place, and in this case, it overwrites the file that was already there, making your change permanent. Think you got it? Great! Let s let your users play with their images some more, shall we? Adding Captions A special group of functions allow you to add captions (or a copyright notice or other text) to your images. PHP/GD is relatively advanced in allowing you to control the size and type of font that is used, even allowing you to load your own font on demand. While you re absolutely encouraged to experiment with all the cool font functions available to you, we will try and keep it simple here to get you started. That being said, let s get to it! 214 Chapter 7
From our experience, we can recommend PHP Web Hosting services, if you need affordable webhost to host and run your web application.

they submitted were saved successfully, so this mode (Adult web hosting)

Monday, July 23rd, 2007

they submitted were saved successfully, so this mode lets you do just that. You see the prime example of that later in the script when you add the lines Your image has been modified. ; echo ; } else { You show the Your image has been modified line just to let users know what s going on. You also show the image again, so they can see their changes in action. You left out the size and when the image was uploaded, because users already saw that info when they first uploaded the thing. In the following lines, you added a form to give users the black and white option:


Modifying Your Image

Please choose if you would like to modify your image with any of the following options. If you would like to preview the image before saving, you will need to hit your browser s back button to return to this page. Saving an image with any of the modifications listed below cannot be undone.

> black & white

Since we re on the subject of the new form, look at your newly created modifyimage.php file. Everything should look pretty standard, until you get to this line: $image = imagecreatefromjpeg( $image_filename ); Remember the five-step conversion process? There is a similar process when simply altering images. First, you create a GD-friendly duplicate of your source image, which you did in the line above. Next you do whatever it is you want to do to your GD-friendly image, as seen in the following lines: if ($bw == on ) { imagefilter($image, IMG_FILTER_GRAYSCALE); } 213 Manipulating and Creating Images with PHP
In case you need affordable webhost to host your website, our recommendation is ecommerce web host services.

If you preview your image in black and (Linux web host)

Monday, July 23rd, 2007

If you preview your image in black and white, you will get a screen with nothing but the image. Try hitting your browser s back button and try saving the file in black and white this time. You should see something like that shown in Figure 7-5 (of course in this book the images always show up in black and white, but bear with us, okay?). Figure 7-5 How It Works If you look at the lines you added in showimage.php, you see the following lines first: //**INSERT THE FOLLOWING LINE: if (isset($_REQUEST[ mode ])) { $mode = $_REQUEST[ mode ]; } else { $mode = ; } //**END OF INSERT You have added this variable because in modifyimage.php you send users back to this page to show them their newly modified image. You want to send them some kind of confirmation that the change(s) 212 Chapter 7
You need excellent and relaible webhost company to host your web applications? Then pay a visit to Inexpensive Web Hosting services.

imagefilter($image, IMG_FILTER_GRAYSCALE); } if ($action == preview ) (Web hosting account) {

Sunday, July 22nd, 2007

imagefilter($image, IMG_FILTER_GRAYSCALE); } if ($action == preview ) { header( Content-type:image/jpeg ); imagejpeg($image); } if ($action == save ) { imagejpeg($image, $image_filename); $url = location:showimage.php?id= . $id . &mode=change ; header($url); } ?> 3. Now, try this out. You don t need to upload another image, because you haven t changed anything in that step of the process. Go to http://localhost/showimage.php?id=1 (or whatever your specific URL is). You should see something similar to that in Figure 7-4. Figure 7-4 211 Manipulating and Creating Images with PHP
Check Tomcat Web Hosting services for best quality webspace to host your web application.