二款php 图片等比例缩放

作者:简简单单 2010-09-22
 代码如下 复制代码

header("content-type:image/jpeg");
$filename = hsdir.'/mljntc2p.jpg';
$im = imagecreatefromjpeg($filename);
$h=imagesy($im);//获得目标图片高度
$new_img_width  = 257;
$new_img_height = 522;

$newim = imagecreate($new_img_width, $new_img_height);
$white = imagecolorallocate($newim, 255,255,255); //设置背景颜色
imagecopyresized($newim, $im, 0, 0, 0, 0, $new_img_width, $new_img_height, $new_img_width, $new_img_height);
imagefilledrectangle($newim,0,$h,$new_img_width,$new_img_height,$white);
//填充  目标图片高度作为起驶y坐标 以指定截取宽高为结束坐标
imagejpeg($newim);
imagedestroy($newim);
imagedestroy($im);
?>

代码二

 代码如下 复制代码

header("content-type:image/jpeg");
$filename = 'myface.jpg';
$im = imagecreatefromjpeg($filename);
$new_img_width  = 80;
$new_img_height = 150;
$newim = imagecreate($new_img_width, $new_img_height);
$white = imagecolorallocate($newim, 255,255,255); //设置背景颜色
imagecopyresized($newim, $im, 0, 0, 0, 0, $new_img_width, $new_img_height, $new_img_width, $new_img_height);
imagejpeg($newim);
imagedestroy($newim);
imagedestroy($im);
?>

相关文章

精彩推荐