View Full Version : Image resizing: server side
davidshaw89
18th September 2009, 16:39
I have looked around a bit for a solution to this, but not to much success. On the off chance that anyone on here knows of a solution:
I'm looking for some sort of script that can integrate with the existing back-end of a website to resize image files to a few different sizes upon upload (gif or jpeg).
For example, when creating a new product, I would upload a photo of size 1000x1000px and the website would automatically scale down and save the photo in a few different sizes to the folder of my choice.
So if I were to go into the folder afterwards, I would find the following files:
productxxxx_60x60px.gif
productxxxx_500x500px.gif
productxxxx_1000x1000px.gifThe back-end of the site is in php so this would be ideal, but it doesnt matter what language the script uses because I can integrate this no problem.
If there is nothing standard (without a watermark) available on the market, rough coding costs would be appreciated.
Currently all the scaling is done manually by uploading 3 individual files so I am just looking at a way of simplifying/saving time with this process.
Thanks in advance :)
openmind
18th September 2009, 17:22
There is about a billion different ways of doing this with PHP:
http://www.google.co.uk/search?q=resize+images+php&sourceid=navclient-ff&ie=UTF-8&rlz=1B3GGGL_enGB292GB292
Be aware though if you are resizing gifs they are going to look like cack afterwards. Better to use JPG or PNG files.
awebapart.com
18th September 2009, 17:52
PHP can handle resizing most gifs OK, as long as you temporarily convert them to true colour as part of the resizing process first (you have to do something similar if you do this manually too in photoshop). In PHP you will need to make use of the ImageCreateTrueColor function to do this. Try out www.shrinkpictures.com (http://www.shrinkpictures.com) with a gif.
The main issue which is more difficult with shrinking gifs is handling either transparency (difficult) or animated gifs (impossible).
There will be issues with gifs that should really have been jpgs in the first place due to their image makeup (photos, gradients, many colours), and these should really be converted first.
davidshaw89
18th September 2009, 18:36
Thanks, that really helps. I was looking for something off the shelf that I could integrate into the back-end.
Image transparency isnt an issue, and neither is animated gifs so converting gif should be just as easy as jpeg if this is the case?
I've had a look at shrinkpictures.com and that does exactly what I want, except I wouldn't need to choose the size options, and I'm looking to convert the image 3 times in one go. I get the feeling I might be asking a little too much.
Perhaps an offline dedicated resizing tool and then uploading all 3 individually would put less strain on the server anyway :|
ozbon
18th September 2009, 19:02
I've written a few things that do this on upload of files - I haven't done it for existing files, but I don't think that would be a massive problem either.
Depending on the size of the images initially, it won't be a massive hit on the server during the upload/resize process. It would be if you were resizing them on the fly each time you displayed them, but that's not something you've said about doing, so we'll ignore it for now.
davidshaw89
18th September 2009, 19:21
I've written a few things that do this on upload of files - I haven't done it for existing files, but I don't think that would be a massive problem either.
Depending on the size of the images initially, it won't be a massive hit on the server during the upload/resize process. It would be if you were resizing them on the fly each time you displayed them, but that's not something you've said about doing, so we'll ignore it for now.
No, I definitely don't want them resized on the fly - the primary reason for resizing them in the first place is so that I can shorten the load times for the user.
It isn't for existing files - it is for the upload of files.
How complicated was it to write this? and could you pm me about rough costs?
Cheers,
Kev Jaques
19th September 2009, 12:31
This might be worth looking at http://shiftingpixel.com/2008/03/03/smart-image-resizer/
It caches the different sizes in a dir on the server from 1 big image, there is also browser cache checking for users too.