header(
"Content-type: image/jpeg"
);
$file
=
"10k.jpg"
;
$percent
= 1.5;
//图片压缩比
list(
$width
,
$height
) =
getimagesize
(
$file
);
//获取原图尺寸
//缩放尺寸
$newwidth
=
$width
*
$percent
;
$newheight
=
$height
*
$percent
;
$src_im
= imagecreatefromjpeg(
$file
);
$dst_im
= imagecreatetruecolor(
$newwidth
,
$newheight
);
imagecopyresized(
$dst_im
,
$src_im
, 0, 0, 0, 0,
$newwidth
,
$newheight
,
$width
,
$height
);
imagejpeg(
$dst_im
);
//输出压缩后的图片
imagedestroy(
$dst_im
);
imagedestroy(
$src_im
);
时间: 2024-11-25 11:46:07