EllisLab text mark
Advanced Search
     
Image Lib: How to maintain_ratio with MINIMUM short side?
Posted: 15 May 2012 04:15 AM
Joined: 2011-06-24
101 posts

1. I have a thumbnail slot of 32 by 32 pixels
2. I will create thumbnails from both horizontal and vertical images
3. I need to maintain aspect ratio

How do I make sure I don’t end up with white space in the thumbnails?

Scenario:
Image: width: 431 pixels, height: 600

$config['maintain_ratio'TRUE;
$config['master_dim''auto';
$config['width'32;
$config['height'32

This gives me an image with a height of 32 and a width of ONLY 23.

How do I make sure that I always FILL the whole thumbnail slot wether the image is horizontal or vertical?

 
Posted: 15 May 2012 07:07 AM   [ # 1 ]   [ Rating: 0 ]
Avatar
Joined: 2011-05-31
87 posts

You need to use the crop function.

Grab the image dimensions from the upload class and use them to calculate the coordinates needed for cropping.

 
Posted: 15 May 2012 07:13 AM   [ # 2 ]   [ Rating: 0 ]
Joined: 2007-11-23
332 posts

Take a quick look at http://www.matmoo.com/digital-dribble/codeigniter/image_moo/

It’s saved me a load of time when dealing with the Image Library in CI…

 
Posted: 15 May 2012 08:48 AM   [ # 3 ]   [ Rating: 0 ]
Joined: 2011-06-24
101 posts

Thanks, I’m going for the native CI image lib. And I do not want cropping. I’ll see what I can come up with.