Ask your WordPress questions! Pay money and get answers fast! Comodo Trusted Site Seal
Official PayPal Seal

timthumb crop to a square WordPress

  • SOLVED

Well, Hello

I am using timthumb to scale logo files (added as media attachments in post meta) that I have on my website, the logo's are of varying size but are typically horizontal rectangles. I am going to be including these images in an 80*80 space, so am setting just the width as this works well for the horizontal ones - the images are scaled down to fit correct width and fit in the box nicely

The problem I have is with images that are portrait, they scale down to the correct width but the height is longer than the area.

Please can you help me by providing code to ensure that the image will fit into an area 80*80. One of the dimensions should always be 80, but the other I guess could be smaller and the image centred to ensure it appears to fit the space

You can see an example of this issue at the link below for the company Freeth Cartwright
http://legalgraduate.com/companies/

I am not interested in cropping images manually

Thanks!

Answers (4)

2011-11-10

Sébastien | French WordpressDesigner answers:

w=80&h=80&zc=1


[[LINK href="http://legalgraduate.gradvantage.com/wp-content/themes/unisphere_corporate/timthumb.php?src=/wp-content/uploads/2011/11/Squire-Sanders-Dempsey-LLP-e1279043675571.gif&w=80&h=80&zc=1"]]http://legalgraduate.gradvantage.com/wp-content/themes/unisphere_corporate/timthumb.php?src=/wp-content/uploads/2011/11/Squire-Sanders-Dempsey-LLP-e1279043675571.gif&w=80&h=80&zc=1[[/LINK]]

instead of
[[LINK href="http://legalgraduate.gradvantage.com/wp-content/themes/unisphere_corporate/timthumb.php?src=/wp-content/uploads/2011/11/Squire-Sanders-Dempsey-LLP-e1279043675571.gif&w=80"]]http://legalgraduate.gradvantage.com/wp-content/themes/unisphere_corporate/timthumb.php?src=/wp-content/uploads/2011/11/Squire-Sanders-Dempsey-LLP-e1279043675571.gif&w=80[[/LINK]]

in this case your image is cropped
if you prefere you can just deform the image with zc=0
like that
[[LINK href="http://legalgraduate.gradvantage.com/wp-content/themes/unisphere_corporate/timthumb.php?src=/wp-content/uploads/2011/11/Squire-Sanders-Dempsey-LLP-e1279043675571.gif&w=80&h=80&zc=0"]]http://legalgraduate.gradvantage.com/wp-content/themes/unisphere_corporate/timthumb.php?src=/wp-content/uploads/2011/11/Squire-Sanders-Dempsey-LLP-e1279043675571.gif&w=80&h=80&zc=0[[/LINK]]


Sébastien | French WordpressDesigner comments:

@npeplow > is it ok ? :-)


npeplow comments:

Hi Seb

I have updated the link but its deforming all the images

http://gradvantage.com/wp-content/themes/unisphere_corporate/timthumb.php?src=/wp-content/uploads/2011/11/ffw_logo_print.gif&w=80&h=80&zc=0


Sébastien | French WordpressDesigner comments:

Use zc=1 in this case


npeplow comments:

In this case it crops the image

http://gradvantage.com/wp-content/themes/unisphere_corporate/timthumb.php?src=/wp-content/uploads/2011/11/306.jpg&w=80&h=80&zc=1


npeplow comments:

got it working with zx=2, thanks

2011-11-10

Maor Barazany answers:

I think you may write a small function that will get as source the image and determine if it is portrtait - then crop with timthumb by height, if not - crop like you do now.

Something like this:


<?php
function isPortrait($url) {
$dimenstions = getimagesize($url);
$width = dimenstions[0];
$height = dimenstions[1];
if ($width > $height) return false;
else return true;
}
?>


Then you may check fr every image before timthumbing it
if isPortrait($url) {
// code for timthumb cropping rectangle images
}
else {
//code for cropping the portrait images
}


npeplow comments:

Hi Maor

Thanks for the suggestion, its really smart but I think the timthumb property is the best way for me.

Nick

2011-11-10

Luis Cordova answers:

have you seen Imaging Library?

2011-11-10

dr_killpatient answers:

Darn Sébastien
You was faster ;)

Here is the explain
http://www.binarymoon.co.uk/2011/03/timthumb-proportional-scaling-security-improvements/