[thelist] Adding to the Login System with Admin Features: Two Questions

Hugh Miller hmiller at cfpress.co.uk
Wed Feb 11 08:48:37 CST 2009


You would typically use a the PHP GD functions to do this; It can be 
achieved by a very simple bit of code, but you have to think about what 
your users will submit, portrait, square and landscape images, some 
widescreen, some self cropped first etc etc. This makes it quite a bit 
more challenging.

Typically thumbnails would be cropped to compensate for this.

Here is what I do:

1. Check an image was actually sent with data
2. Get that image for processing and create a new name (I use a unix 
timestamp plus .jpg to avoid duplication)
    Set the path to full sized images
    Set the path to thumbnails
3. Compare the file I received to jpg, gif and png formats (or else you 
can have a situation where they submit a gif and your jpg processor dies.
4. Get the original filesize and determine your preferred width and 
height for new images
5. Crop and scale the image
    On some scripts at this point I rotate images instead
6. Save the output (and original file if needed)


Before you panic, this is achieved with less than you might think 
because php includes all of the functions that you need.

I've attached a text file with an example of the above workflow, it's 
not a tutorial but the comments that are there tell you what happens in 
each block, this has been lifted from a working example I use and so may 
have some quirks in there that are not really suitable for what you are 
doing (for example there is some offsetting being performed on the crop 
functionality to make the top of a portrait image more important than 
the bottom).



Tony Spiro wrote:
> 2. I am using this fantastic script as well
> http://dottedi.biz/codesamples/forms/upload/upload_file.php to upload user
> profile pics and I need to know how to resize the image on upload so a
> 3000px wide picture is not crammed into a 50px wide space, causing the load
> time to be slow.
> Any help is much appreciated!
> Thanks,
> Tony


This message has been scanned for viruses and
dangerous content by MailScanner, and is
believed to be clean.

-------------- next part --------------
An embedded and charset-unspecified text was scrubbed...
Name: image_upload_resampler.txt
URL: <http://lists.evolt.org/pipermail/thelist/attachments/20090211/621fdcab/attachment.txt>

More information about the thelist mailing list