|
||||
| Register--Login--Top 20 Posters--Search Topics |
Forum Main>>Tutorials>>Making Thumbnails with PHP | ||
Chipmunk![]() Rank:Settler of Bobland Group: Head Administrator Posts: 2867 IP Logged PM ID and RPS ID: 1 PM [Chipmunk] View Member Photo | Last replied to on Sat Jul 10, 2010 04:16:31 Edit Post|Quote This tutorial will teach you how to make thumbnails from an upload script in PHP. I will use a 100*100 thumbnail as an example. You can change the dimensions to whatever you like. We will need to create 2 files, form.php and action.php. You also need to create a folder to store your photos that you created. Make sure that folder is chmodded to 777 so it will be able to create and store the thumbs in that folder. The action.php file should also go in the photos folder. For this script I'll create th folder photos. Now for the form.php file:
Ok, this is the basic form. As you can see if only has 1 field, the field that lets you cchoose the file you want to upload. Note that the input type must be file and enctype must be multipart/form-data in order for this to work, otherwise the file will not upload. The action is action on ../photos/upload.php because thats where the actual form to upload the thumbnails are. Now the action.php file:
This file is a bit complicated. In this file we specify the dimensions of the thumbnail, the types of file extensions that are allowed, what the name of the thumbnail is, creating a thumbnail from the actual picture, and resizing it. First $new_height and $new_width are our specified dimension of the thumbnails, you can change these to whatever you want to suit your needs. Next in $allowed_types, we created an array with the types of files that are allowed to be uploaded. As you can see we listed the common extension and types for .gif and .jpg file extensions. Next with the if(in_array) condition, we check if the file being uploaded was one of the allowed types, if it wasn't, it will display a message "only gifs and jpegs are allowed". If it is one of the allowed types then it will check to see whether it was a .gif or a .jpg and based on that if will either tell it to go to the .gif create image case or the .jpg create image case. $img is actually the variable that holds the created image and the functions @imagecreatefromgif and @imagecreatefromjpg are the two function that actually create a thumnail for either a gif or a jpg image. imagecopyresampled is a function that resizes the image we just created to the dimensions we specified earlier, the fields where I put zeros in are the field where you can specify color dilution within this function. If your just trying to create thumbs, leave these as zeros. $image_p now holds the resampled $img. The next few lines specify the location where the new image created will go and finally the imagegif or imagejpg function will put the new image in the place we specified. Now if you go into your photos folder you should see a 100*100 thumbnail of the image you just created. ----------------------------- Chipmunk, Supreme Administrator | ||
| jalejandrocp Rank:acorn Group: members Posts: 1 IP Logged PM ID and RPS ID: 13319 [PM jalejandrocp] RPS score: 0 RPS challenge | Posted at Wed Aug 08, 2007 21:33:37 Edit post|Quote HELLO, I HAVE MODIFIED THIS CODE TO DO THUMBNAILS, ADDING TO IT 3 LINES OF CODE. IT WAS FOR MAKING THAT THUMBNAILS NOT DESPROPORTIONATE. SORRY FOR MY ENGLISH JUST ADD TE CODE BETWEEN : //between this code... list($width, $height) = getimagesize($_FILES['thefile']['name']); //////////// MY CODE /////////////////////////// Crear tamaño del thumbnail en proporcion a la imagen.// $new_height = 100;// $porc_width = $new_height/$height;// $new_width = $porc_width*$width; $new_width = 100; $porc_height = $new_width/$width; $new_height = $porc_height*$height;//////////// MY CODE ///////////////////////// //... and between this code... $image_p = imagecreatetruecolor($new_width,$new_height); | ||
| aland15 Rank:acorn Group: members Posts: 1 IP Logged PM ID and RPS ID: 24971 [PM aland15] RPS score: 0 RPS challenge | Posted at Tue Oct 27, 2009 00:46:12 Edit post|Quote It's an good idea i really love this and appreciate your work, you know time is term life insurance money an a person is successful if he time timely en cash it, right now now i m doing mcse and hope a great career waits for me with a career oriented job, I hope,airline tickets May IT gives you a great career and I suggest the people to get involved in this certification to serve the nation with blood and intellect.It was a very nice idea! Just wanna say thank you for the information you have shared. Just continue writing this kind of post. I will be your good reader. Thanks again.viagra | ||
| alice Rank:acorn Group: members Posts: 31 IP Logged PM ID and RPS ID: 30842 [PM alice] RPS score: 0 RPS challenge | Posted at Sat Jul 10, 2010 04:16:31 Edit post|Quote I entered my first list of products I found in Albertsons in Oceanside, CA. I didn't do a large shopping trip, just picked up a few things. I'm sure Albertsons has LOTS more 100% California items. I'm shopping at Sprouts in San Marcos tonight. I'll share my 100% CA's from there with you tomorrow! I love this! 642-631 642-654 642-661 642-681 | ||
Page: 1 |