日期:2013-04-24  浏览次数:20472 次

PHP的GD扩展提供了两个函数来缩放图像:
ImageCopyResized(dest, src, dx, dy, sx, sy, dw, dh, sw, sh);
ImageCopyResampled(dest, src, dx, dy, sx, sy, dw, dh, sw, sh);

ImageCopyResized( )函数在所有GD版本中有效,但其缩放图像的算法比较粗糙,可能会导致图像边缘的锯齿。GD 2.x中新增了一个ImageCopyResampled( )函数,其像素插值算法得到的图像边缘比较平滑(但该函数的速度比ImageCopyResized()慢)。

来看一个例子,我们将这个图缩小四倍:
<?php

 $src 
ImageCreateFromJPEG('php.jpg');

 
$width ImageSx($src);
 
$height ImageSy($src);
 
$x $width/2$y $height/2;
 
$dst ImageCreateTrueColor($x,$y);
 
ImageCopyResized($dst,$src,0,0,0,0,$x,