I am afraid there is none.
'Good' image scaling rely om the scaler knowing and recognizing what is important in the image, and computers are not good at making such judgement calls. In rescaling a picture of a girl you and I would almost certainly agree that the girl-contour was the important part. But the computer may as easily focus on the floral pattern on her dress and retain that while losing the contour.
When rescaling something must be thrown away. how to decide what.
Even highquality image processing programs have this problem. if you try to rescale a line drawing you will typically lose some of the lines completely leawing the scaled image as a unconnected mess of apparently random pieces of line. (Try it). Similarly a photo with many detalis (eg panorama of audience at sporting event) will often become utterly unrecognizable if scaled down.
Often for thumbs I do not even try to rescale the image, but crop it instead. eg for that image of a girl I might cut out the face area and the thumb is then a portrait with very little scaling. You can get very beautiful thumbs that way, but I shudder at the thought of trying to automate the process. A computer program would as happily crop arund the winebottle on the table or whatever other recognizable 'cohesive unit' it could find in the picture.
The less you scale it the greater are the chance that the image will still be recognizable, so if autumation is an absolute demand I would recommend that you make your thumbs bigger, twice as big a thumb give you something like 4 times as good a chance of getting a worthwhile thumb.
regards JakobA
Main Topics
Browse All Topics





by: alakritiPosted on 2005-09-25 at 18:23:23ID: 14955884
<?php
image.png" ,"/path/to /small/ima ge.png","p mg"); image2.png ","/path/t o/small/im age2.png", "png");
,$str_imag e_dest ,$str_output_type)
frompng($s tr_image_s rc);
image, $int_new_width); new_width, $int_new_h eight);
t_image, $res_src_image, 0, 0, 0, 0, $int_new_width, $int_new_height, imagesx($res_src_image), imagesy($res_src_image));
e, $int_new_width, $int_new_height);
, &$res_scaled_image, $int_new_width, $int_new_height);
str_image_ dest); tr_image_d est); tr_image_d est);
77);
image, $int_new_width) {
mage, $int_new_height) {
, $int_new_width, $int_new_height){
< imagesy($res_src_image)){
image, $int_new_width);
new_width, $int_new_h eight); t_image, $res_src_image, 0, 0, 0, 0, $int_new_width, $int_new_height, imagesx($res_src_image), imagesy($res_src_image));
mage, $int_new_height);
new_width, $int_new_h eight); t_image, $res_src_image, 0, 0, 0, 0, $int_new_width, $int_new_height, imagesx($res_src_image), imagesy($res_src_image));
$res_src_image, $int_new_width, $int_new_height){ mage) - $int_new_width) / 2)); mage) - $int_new_height) / 2));
t_image, $res_src_image, 0, 0, $int_crop_x, $int_crop_y,$int_new_width , $int_new_height, $int_new_width, $int_new_height);
createThumb("/path/to/big/
createThumb("/path/to/big/
function createThumb($str_image_src
{
$int_new_width=125;
$int_new_height=125;
$res_src_image=imagecreate
$int_new_height_tmp = get_image_height($res_src_
$res_dst_image = imagecreatetruecolor($int_
// Check proportions are the same.
if(($int_new_height / $int_new_width) == ( imageSY($res_src_image)/ imageSX($res_src_image))){
// Resize Image
imagecopyresampled($res_ds
} else {
// Scale Image
$res_scaled_image = scale_image(&$res_src_imag
// Crop Image
crop_image(&$res_dst_image
}
switch($str_output_type){
default:
case"jpeg":
imagejpeg($res_dst_image,$
break;
case"gif":
imagegif($res_dst_image,$s
break;
case"png":
imagepng($res_dst_image,$s
break;
chmod("$str_image_dest",07
}
function get_image_height($res_src_
// Get Image Dimensions
$int_old_x = imageSX($res_src_image);
$int_old_y = imageSY($res_src_image);
// Determine if width is larger or smaller then height
if ($int_old_x < $int_old_y) {
$int_ratio = $int_old_y / $int_old_x;
$int_new_height = round($int_ratio * $int_new_width);
} else if ($int_old_x > $int_old_y) {
$int_ratio = $int_old_x / $int_old_y;
$int_new_height = round($int_ratio * $int_new_width);
} else if ($int_old_x == $int_old_y) {
$int_new_height = $int_new_width;
}
return $int_new_height;
}
function get_image_width($res_src_i
// Get Image Dimensions
$int_old_x = imageSX($res_src_image);
$int_old_y = imageSY($res_src_image);
// Determine if width is larger or smaller then height
if ($int_old_y < $int_old_x) {
$int_ratio = $int_old_x / $int_old_y;
$int_new_width = round($int_ratio * $int_new_height);
} else if ($int_old_y > $int_old_x) {
$int_ratio = $int_old_y / $int_old_x;
$int_new_width = round($int_ratio * $int_new_height);
} else if ($int_old_y == $int_old_x) {
$int_new_width = $int_new_height;
}
return $int_new_width;
}
function scale_image($res_src_image
$int_orig_width = $int_new_width;
$int_orig_height = $int_new_height;
if(imagesx($res_src_image)
// Height Larger Then Width
// Get New Width
$int_width_diff = $int_new_width - imagesx($res_src_image);
$int_new_width = imagesx($res_src_image) + $int_width_diff;
// Get New Height
$int_new_height = get_image_height($res_src_
$res_dst_image = imagecreatetruecolor($int_
imagecopyresampled($res_ds
} else{
// Width Larger Then Height or Equal
// Get New Height
$int_height_diff = $int_new_height - imagesy($res_src_image);
$int_new_height = imagesy($res_src_image) + $int_height_diff;
// Get New Width
$int_new_width = get_image_width($res_src_i
$res_dst_image = imagecreatetruecolor($int_
imagecopyresampled($res_ds
}
return $res_dst_image;
}
function crop_image($res_dst_image,
// Get XY Cordinates for Crop
$int_crop_x = floor(((imagesx($res_src_i
$int_crop_y = floor(((imagesy($res_src_i
imagecopyresampled($res_ds
}
?>