Archive for July, 2007

Web site management - Please choose if you would like to modify

Sunday, July 22nd, 2007

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

2. Next, you want to create a new file that will modify your image accordingly. Open your browser and type the following, saving it as modifyimage.php: Check Tomcat Web Hosting services for best quality webspace to host your web application.

Web server application - } else { $mode = ; } //**END

Sunday, July 22nd, 2007

} else { $mode = ; } //**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); ?>

So how does it feel to be famous?

Your image has been modified. ; echo ; } else { ?>

Here is the picture you just uploaded to our servers:

align= left >
It is pixels wide and pixels high.
It was uploaded on by .


Modifying Your Image

209 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.

Free php web host - You also then can destroy your temporary images,

Saturday, July 21st, 2007

You also then can destroy your temporary images, as in the lines that follow: imagedestroy($image_old); imagedestroy($image_jpg); In summary, you have either renamed your JPG files to be image_id.jpg, or you have created duplicate images and saved them as JPG files with the name image_id.jpg. Now you can reference the images the same way every time. The script also relocates you to a new file, showimage.php, which basically pulls the information you just entered into the database, looks it up again, then spits it back to the browser. The difference is that you can access the showimage.php page any time, and for any image ID. This file is also going to be where you allow your users to modify their image to include captions, watermarks, and all kinds of other fun things. Black and White Now that you ve got a directory full of images, what comes next? To play with them of course! What if you wanted to allow your users to make their images black and white? Let s add that option to your showimage page, so your users can choose whether or not they want to see their image in grayscale. You will be using the imagefilter() function, which can do many things, only one of which is to convert the image to grayscale. This function can also make a negative of your image, alter the brightness or contrast of your image, emboss, blur, smooth, detect edges within and colorize your image. Whew! It s a pretty powerful function, and one you want to remember. (You can find complete syntax for using this function and the filter types at http://us2.php.net/manual/en/function.imagefilter.php.) You can use this function to clean up or create funky versions of uploaded photos, or better yet, transfer that power over to your users! Try It Out Adding Grayscale In this exercise, you ll add just one of the imagefilter() features to your site. You ll give users the option to show their image in grayscale. 1. Open showimage.php and make the following highlighted changes: Searching for affordable and proven webhost to host and run your servlet applications? Go to Linux Web Hosting services and you will find it.

Here you are saying if the file is (Yahoo web space)

Saturday, July 21st, 2007

Here you are saying if the file is a JPG file, you just want to rename it to match your image ID, plus the .jpg extension. Piece of cake, right? Otherwise, if the file is a GIF or a PNG, you want to use the appropriate function to deal with them. You first check to see if the file is a GIF file: } else { if ($type == 1) { $image_old = imagecreatefromgif($ImageName); imagecreatefromgif() is the appropriate function because your source image is in a GIF format. Likewise if the image was a PNG image, you would use the imagecreatefrompng function: } elseif ($type == 3) { $image_old = imagecreatefrompng($ImageName); } Now that you have your GD-friendly source image, you need to go step 2 of the conversion list presented earlier and create a GD-friendly temporary destination image. You do this in the next line: $image_jpg = imagecreatetruecolor($width, $height); You use the imagecreatetruecolor() function to maintain color quality in your image, and because you want your destination image to be identical in size to the source image, you use the $width and $height variables that were obtained from the getimagesize function earlier in the script. Now you can proceed to step 3 of the conversion list copy the temporary source image into the temporary destination image. You do this in the next line: imagecopyresampled($image_jpg, $image_old, 0, 0, 0, 0, $width, $height, $width, $height); You use imagecopyresampled to maintain the quality of your image. As you can see, you denote the destination image, the source image, starting coordinates (x, y) of both images, and the width and height of each image. If you only wanted to copy a portion of the source image into your destination image, you could do this through the coordinates and the width/height variables. Next, you have to save your image somewhere to make it permanent, as you can see in the next line: imagejpeg($image_jpg, $newfilename); This is where the actual conversion takes place. Before this line, your temporary images were generic. You decide to make the destination file a JPG with the imagejpeg function. You could also have used imagepng or imagegif, but again, you want to work with JPGs because the majority of your uploaded files will be photos. In this function, you name the new temporary source file (your previous destination file) and the new permanent destination file. It s important to note that you needed to include the path name in the variable $newfilename, which you did above. 207 Manipulating and Creating Images with PHP
From our experience, we are can tell you that you can find a reliable and cheap webhost service at Java Web Hosting services.

2. Open your text editor and type the (Net web server)

Saturday, July 21st, 2007

2. Open your text editor and type the new showimage.php file as shown:

So how does it feel to be famous?

Here is the picture you just uploaded to our servers:

align= left >
It is pixels wide a nd pixels high.
It was uploaded on by . 3. If you save the file, load it in your browser, and upload your picture, you will notice that you basically get the same screen as before (with a few minor tweaks). How It Works Let s look at the main section that you added to your program, and let s take it line by line. First, we will deal with the JPG files because they are already in the format you want. if ($type == 2) { rename($ImageName, $newfilename); 206 Chapter 7
If you are looking for cheap and quality webhost to host and run your website check Jboss Web Hosting services.

Michigan web site - $insert = INSERT INTO images (image_caption, image_username, image_date)

Saturday, July 21st, 2007

$insert = INSERT INTO images (image_caption, image_username, image_date) VALUES ( $image_caption , $image_username , $today ) ; $insertresults = mysql_query($insert) or die(mysql_error()); $lastpicid = mysql_insert_id(); //change the following line: $newfilename = $ImageDir . $lastpicid . .jpg ; //**insert these lines if ($type == 2) { rename($ImageName, $newfilename); } else { if ($type == 1) { $image_old = imagecreatefromgif($ImageName); } elseif ($type == 3) { $image_old = imagecreatefrompng($ImageName); } // convert the image to jpg $image_jpg = imagecreatetruecolor($width, $height); imagecopyresampled($image_jpg, $image_old, 0, 0, 0, 0, $width, $height, $width, $height); imagejpeg($image_jpg, $newfilename); imagedestroy($image_old); imagedestroy($image_jpg); } $url = location: showimage.php?id= . $lastpicid; header($url); //**end of inserted lines } ?>

  • You are currently browsing the PHP Web Hosting, Tomcat, JSP, J2EE, Servlets, Struts - PHP4, PHP5 Programming Blog weblog archives for July, 2007.

  • Archives

  • Categories