For non-distorted square thumbs (first the thumb is created with a minimum height or width -depending on if the image is horizontal or vertical- and then the final thumbnail is extracted from the center -this, of course, won't affect to already square images), follow these steps:
1.- Open includes/image_utils.php
2.- Find the function create_thumbnail (near the end), it's all this code:
function create_thumbnail($src, $dest, $quality, $dimension, $resize_type) {
global $convert_options;
if (file_exists($dest)) {
@unlink($dest);
}
$image_info = (defined("IN_CP")) ? getimagesize($src) : @getimagesize($src);
if (!$image_info) {
return false;
}
$width_height = get_width_height($dimension, $image_info[0], $image_info[1], $resize_type);
$resize_handle = "resize_image_".$convert_options['convert_tool'];
if ($resize_handle($src, $dest, $quality, $width_height['width'], $width_height['height'], $image_info)) {
@chmod($dest, CHMOD_FILES);
return true;
}
else {
return false;
}
}
3.- Select all that code and either remove or comment it (the latter is a better option just in case you need the code again).
4.- Paste this code just where the removed code was (or if you just commented it out, paste the code either before of after the commented code -it doesn't matter):
function resize_image_gd_thumb($src, $dest, $quality, $width, $height, $image_info) {
global $convert_options;
$xpos = 0;
$ypos = 0;
if ($width > $height) {
$xpos = ceil((($width - $height) / 2) - ($width - $height));
} elseif ($height > $width) {
$ypos = ceil((($height - $width) / 2)- ($height - $width));
} else {
$xpos = 0;
$ypos = 0;
}
$types = array(1 => "gif", 2 => "jpeg", 3 => "png");
if ($convert_options['convert_gd2']) {
$thumb = imagecreatetruecolor(150, 150);
}
else {
$thumb = imagecreate(150, 150);
}
$image_create_handle = "imagecreatefrom".$types[$image_info[2]];
if ($image = $image_create_handle($src)) {
if ($convert_options['convert_gd2']) {
imagecopyresampled($thumb, $image, $xpos, $ypos, 0, 0, $width, $height, ImageSX($image), ImageSY($image));
}
else {
imagecopyresized($thumb, $image, $xpos, $ypos, 0, 0, $width, $height, ImageSX($image), ImageSY($image));
}
if ($image_info[2] == 3) {
$quality = 9;
}
$image_handle = "image".$types[$image_info[2]];
$image_handle($thumb, $dest, $quality);
imagedestroy($image);
imagedestroy($thumb);
}
return (file_exists($dest)) ? 1 : 0;
}
function create_thumbnail($src, $dest, $quality, $dimension, $resize_type) {
global $convert_options;
if (file_exists($dest)) {
@unlink($dest);
}
$image_info = (defined("IN_CP")) ? getimagesize($src) : @getimagesize($src);
if (!$image_info) {
return false;
}
if ($image_info[0] > $image_info[1]) {
$width = ceil($image_info[0] / ($image_info[1]/150));
$height = 150;
} elseif ($image_info[1] > $image_info[0]) {
$width = 150;
$height = ceil($image_info[1] / ($image_info[0]/150));
} else {
$width = 150;
$height = 150;
}
$resize_handle = "resize_image_".$convert_options['convert_tool']."_thumb";
if ($resize_handle($src, $dest, $quality, $width, $height, $image_info)) {
@chmod($dest, CHMOD_FILES);
return true;
}
else {
return false;
}
}
5.- In this code, look for the number 150 and replace it with the size you want for your thumbs (if you want 80x80 thumbs then replace every 150 with a 80).
That's all. Now, let me tell you this: this should work even if you added some MODs to image_utils.php (like that for an image height bug when resizing, I remember), but just be careful if you modified the file before. And, most importantly, the code I posted will only work if you use GD as your converter (I tested the code with GD2).
Good luck and, please tell me if it worked for you.
Regards.
Forgot to say: if you set 150, or 80, whatever, as the size for your thumbnails, note that samller images will be scaled up (if you set 150 and someone uploads a, say, 100x100 image, it will be resized to fill the 150 pixel space -so remember that the size for your thumbnails will be a fixed size and the best you can do is to not upload images smaller than taht size -anyway, does it make sense to upload images smaller than the thumbnails themselves?).