缩略图图像质量

时间:2015-11-30 16:30:10

标签: php image function png jpeg

任何人都可以帮我这个代码吗?我想更改默认缩略图设置(以避免因压缩而导致质量下降)。

我想添加的代码(对于JPEG):imagejpeg($ new_image,$ old_image,100)



<?php

$updir = '../image/';
$img = 'test1.jpg';

function makeThumbnails($updir, $img)
{
    $thumbnail_width = 216;
    $thumbnail_height = 216;
    $thumb_beforeword = "thumb";
    $arr_image_details = getimagesize("$updir" . "$img"); // pass id to thumb name
    $original_width = $arr_image_details[0];
    $original_height = $arr_image_details[1];
    if ($original_width > $original_height) {
        $new_width = $thumbnail_width;
        $new_height = intval($original_height * $new_width / $original_width);
    } else {
        $new_height = $thumbnail_height;
        $new_width = intval($original_width * $new_height / $original_height);
    }
    $dest_x = intval(($thumbnail_width - $new_width) / 2);
    $dest_y = intval(($thumbnail_height - $new_height) / 2);
    if ($arr_image_details[2] == 1) {
        $imgt = "ImageGIF";
        $imgcreatefrom = "ImageCreateFromGIF";
    }
    if ($arr_image_details[2] == 2) {
        $imgt = "ImageJPEG";
        $imgcreatefrom = "ImageCreateFromJPEG";
    }
    if ($arr_image_details[2] == 3) {
        $imgt = "ImagePNG";
        $imgcreatefrom = "ImageCreateFromPNG";
    }
    if ($imgt) {
        $old_image = $imgcreatefrom("$updir" . "$img");
        $new_image = imagecreatetruecolor($thumbnail_width, $thumbnail_height);
		$white = imagecolorallocate($new_image, 238, 238, 238);
		imagefill($new_image, 0, 0, $white);
		
        imagecopyresized($new_image, $old_image, $dest_x, $dest_y, 0, 0, $new_width, $new_height, $original_width, $original_height);
        $imgt($new_image, "$updir" . "$thumb_beforeword" . '_' . "$img");
    }
}

makeThumbnails($updir, $img)

?>
&#13;
&#13;
&#13;

我在多个位置添加了具有正确参数的代码,但它似乎没有任何效果。谁知道我做错了什么?

此致 测验

0 个答案:

没有答案