Many of you want to display your images just right on your site and the majority of you use Tim Thumb script for quick easy cropping and quality control. One of the flaws in Tim Thumb script is that you can’t position the image exactly were you want to crop, you only get a compass cropping system.
- North = t, tl, lr, tr, rt
- South = b, bl, lb, br, rb
- West = l, tl, lt, bl, lb
- East = r, tr, rt, br, rb
The script basically calculates the height and width of the image and then by the size of the image you want it to be. I find my self in needing something a bit more specific that will allow me to crop a large image to a specific area.
So i decided to add my own combination’s by adding a divider. I’m still testing this out my self and so far it is working so if you wish to use it for yourself you are quite welcome to add the following code to the Tim Thumb script.
Simple open the timthumb.php and locate positional cropping. On the last break; before default: add the following and then save.
case 'ml2':
$src_x = $width/2; // Divides the width by 2
break;
case 'ml3':
$src_x = $width/3; // Divides the width by 3
break;
case 'ml4':
$src_x = $width/4; // Divides the width by 4
break;
case 'ml5':
$src_x = $width/5; // Divides the width by 5
break;
case 'ml6':
$src_x = $width/6; // Divides the width by 6
break;
case 'ml7':
$src_x = $width/7; // Divides the width by 7
break;
This allows you to position the image exactly were you want it in the middle from the left.
To add this mod to your image simply add a=ml0 in your html image string. Change the zero to the number you want to use.
I will add other combination’s in the future.
Enjoy.
Continue Reading