Welcome Guest, Not a member yet? Register   Sign In
How do I make multiple thumbails for the same image with image_lib?

I'm going to assume that you'll need those exact sizes without aspect ratio distortion. This means that you'll have to resize first and then crop.

Here's how I approach it (logic only, no code, only for the first size, you should be able to figure out the rest):

- Upload the image and get it's width and height. Say it's 1024 by 786, so it's ar is 1.3 : 1
- The intended size is 582 x 350, ar (aspect ratio) 1.66 : 1
- Now you need to figure out if you'll need to crop horizontally or vertically, seeing as the original's aspect ratio is smaller than the inteded size, you'll need to crop vertically. A higher AR (which means it's more of a panorama image) will need horizontal cropping.
In php you can do this with simple math!
- We need to crop vertically, so we'll want to resize based on width. Resize your image to a width of 582, keep the aspect ratio and use create_thumb, making sure you got a copy and don't waste your original (you'll probably want to keep that...).
- Now you should have an image with a size of about 582*447 pixels.
- All that's left to do is crop now. Time to calculate the x_axis, y_axis, width and height. We know the x_axis has to be 0 and the width 582 (as thats' what we ended up with our resize). Our height has to be 350, so all that's left now is to ($orig_height - 350) / 2 which will give you your y_axis. Now crop.

I hope that's about clear enough. The only thing I can do to make it more clear is to give you the actual code...

Messages In This Thread
How do I make multiple thumbails for the same image with image_lib? - by El Forum - 10-20-2008, 07:36 AM

Theme © iAndrew 2016 - Forum software by © MyBB