bruder
10-06-2008, 01:20
привет. Делаю ресайз картинки, она при разном качестве остается одного и тогоже размера! Почему так? Да и качество не ухудшается, просто не делает и все. Помогите кто знает. Попробуйте сами на большой картинке. Пример вызова
resizejpeg("", "1.jpg", 600, 600, 300, 150);
function resizejpeg($dir, $img, $max_w, $max_h, $th_w, $th_h)
{
// get original images width and height
list($or_w, $or_h, $or_t) = getimagesize($dir.$img);
// make sure image is a jpeg
if ($or_t == 2) {
// obtain the image's ratio
$ratio = ($or_h / $or_w);
// original image
$or_image = imagecreatefromjpeg($dir.$img);
// resize image
if ($or_w > $max_w || $or_h > $max_h) {
// first resize by width (less than $max_w)
if ($or_w > $max_w) {
$rs_w = $max_w;
$rs_h = $ratio * $max_h;
} else {
$rs_w = $or_w;
$rs_h = $or_h;
}
// then resize by height (less than $max_h)
if ($rs_h > $max_h) {
$rs_w = $max_w / $ratio;
$rs_h = $max_h;
}
// copy old image to new image
$rs_image = imagecreatetruecolor($rs_w, $rs_h);
imagecopyresampled($rs_image, $or_image, 0, 0, 0, 0, $rs_w, $rs_h, $or_w, $or_h);
} else {
$rs_w = $or_w;
$rs_h = $or_h;
$rs_image = $or_image;
}
// generate resized image
imagejpeg($rs_image, $dir.'gr_'.$img, 100);
$th_image = imagecreatetruecolor($th_w, $th_h);
// cut out a rectangle from the resized image and store in thumbnail
$new_w = (($rs_w / 4));
$new_h = (($rs_h / 4));
imagecopyresampled($th_image, $rs_image, 0, 0, 0, 0,$new_w, $new_h, $rs_w, $rs_h);
// generate thumbnail
imagejpeg($th_image, $dir.'thumb_'.$img, "30");
return true;
}
// Image type was not jpeg!
else {
return false;
}
}
?>
дополню: imagejpeg($th_image, $dir.'thumb_'.$img, "30");
30 это качество. При таком качестве IfranViewer ужимает картику в 10 раз!
resizejpeg("", "1.jpg", 600, 600, 300, 150);
function resizejpeg($dir, $img, $max_w, $max_h, $th_w, $th_h)
{
// get original images width and height
list($or_w, $or_h, $or_t) = getimagesize($dir.$img);
// make sure image is a jpeg
if ($or_t == 2) {
// obtain the image's ratio
$ratio = ($or_h / $or_w);
// original image
$or_image = imagecreatefromjpeg($dir.$img);
// resize image
if ($or_w > $max_w || $or_h > $max_h) {
// first resize by width (less than $max_w)
if ($or_w > $max_w) {
$rs_w = $max_w;
$rs_h = $ratio * $max_h;
} else {
$rs_w = $or_w;
$rs_h = $or_h;
}
// then resize by height (less than $max_h)
if ($rs_h > $max_h) {
$rs_w = $max_w / $ratio;
$rs_h = $max_h;
}
// copy old image to new image
$rs_image = imagecreatetruecolor($rs_w, $rs_h);
imagecopyresampled($rs_image, $or_image, 0, 0, 0, 0, $rs_w, $rs_h, $or_w, $or_h);
} else {
$rs_w = $or_w;
$rs_h = $or_h;
$rs_image = $or_image;
}
// generate resized image
imagejpeg($rs_image, $dir.'gr_'.$img, 100);
$th_image = imagecreatetruecolor($th_w, $th_h);
// cut out a rectangle from the resized image and store in thumbnail
$new_w = (($rs_w / 4));
$new_h = (($rs_h / 4));
imagecopyresampled($th_image, $rs_image, 0, 0, 0, 0,$new_w, $new_h, $rs_w, $rs_h);
// generate thumbnail
imagejpeg($th_image, $dir.'thumb_'.$img, "30");
return true;
}
// Image type was not jpeg!
else {
return false;
}
}
?>
дополню: imagejpeg($th_image, $dir.'thumb_'.$img, "30");
30 это качество. При таком качестве IfranViewer ужимает картику в 10 раз!