imagejpeg php 300dpi,PHP中高效的JPEG图像大小调整

这是我在项目中使用的php.net文档的一个片段,工作正常:

function fastimagecopyresampled (&$dst_image, $src_image, $dst_x, $dst_y, $src_x, $src_y, $dst_w, $dst_h, $src_w, $src_h, $quality = 3) {

// Plug-and-Play fastimagecopyresampled function replaces much slower imagecopyresampled.

// Just include this function and change all "imagecopyresampled" references to "fastimagecopyresampled".

// Typically from 30 to 60 times faster when reducing high resolution images down to thumbnail size using the default quality setting.

// Author: Tim Eckel - Date: 09/07/07 - Version: 1.1 - Project: FreeRingers.net - Freely distributable - These comments must remain.

//

// Optional "quality" parameter (defaults is 3). Fractional values are allowed, for example 1.5. Must be greater than zero.

// Between 0 and 1 = Fast, but mosaic results, closer to 0 increases the mosaic effect.

// 1 = Up to 350 times faster. Poor results, looks very similar to imagecopyresized.

// 2 = Up to 95 times faster.  Images appear a little sharp, some prefer this over a quality of 3.

// 3 = Up to 60 times faster.  Will give high quality smooth results very close to imagecopyresampled, just faster.

// 4 = Up to 25 times faster.  Almost identical to imagecopyresampled for most images.

// 5 = No speedup. Just uses imagecopyresampled, no advantage over imagecopyresampled.

if (empty($src_image) || empty($dst_image) || $quality <= 0) { return false; }

if ($quality < 5 && (($dst_w * $quality) < $src_w || ($dst_h * $quality) < $src_h)) {

$temp = imagecreatetruecolor ($dst_w * $quality + 1, $dst_h * $quality + 1);

imagecopyresized ($temp, $src_image, 0, 0, $src_x, $src_y, $dst_w * $quality + 1, $dst_h * $quality + 1, $src_w, $src_h);

imagecopyresampled ($dst_image, $temp, $dst_x, $dst_y, 0, 0, $dst_w, $dst_h, $dst_w * $quality, $dst_h * $quality);

imagedestroy ($temp);

} else imagecopyresampled ($dst_image, $src_image, $dst_x, $dst_y, $src_x, $src_y, $dst_w, $dst_h, $src_w, $src_h);

return true;

}

?>

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值