Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

upload image, resiz, crop and add to mysql 1

Status
Not open for further replies.

tyutghf

Technical User
Apr 12, 2008
258
GB
Hi

I want to let users of my website upload an image with a caption, the images will be from a digital camera so will be too big for web so I will need to resize it and then link to it from the database whist making sure that the filename is unique.

There are numerous tutorials on the web but none are recent, the most recent tutorial I found was from 2008 and the requirement was a very old version of php!

Will the old ways still be the best ways or has php improved with image upload and manipulation? Does anyone know of any good tutorials/guides I could follow?

Thanks
 
there is nothing complex about this. the methods have been the same since before 2008 I suspect. Most tutorials will use the GD library.

essentially the process is this:

1. check that the file upload happened properly.
2. generate a unique id. (md5(uniqid('',true))
3. copy the current file to the storage folder and rename it with the unique id and a suffix of _original_
4. get information on the file using getimagesize
5. decide which functions to use as a result of the mime-type retrieved by getimagesize
6. open the original image in gd
7. calculate the new image sizes maintaining appropriate proportion
8. create a new image canvas based on the new images sizes
9. rescale the original image to the new image
10. save the new image with the same uniqueID and a suffix of _hhxww_
11 repeat as necessary for alternative canvas sizes.
12. store whatever metadata (caption etc) you want in a database against the uniqueID.

this is even simpler in practice than it looks in the above explanation.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top