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

timthumb crop to a square WordPress


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

I am not interested in cropping images manually


Answers (4)


Sébastien | French WordpressDesigner answers:


[[LINK href=""]][[/LINK]]

instead of
[[LINK href=""]][[/LINK]]

in this case your image is cropped
if you prefere you can just deform the image with zc=0
like that
[[LINK href=""]][[/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

Sébastien | French WordpressDesigner comments:

Use zc=1 in this case

npeplow comments:

In this case it crops the image

npeplow comments:

got it working with zx=2, thanks


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:

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.



Luis Cordova answers:

have you seen Imaging Library?


dr_killpatient answers:

Darn Sébastien
You was faster ;)

Here is the explain