发布网友 发布时间:2022-05-18 07:42
共1个回答
热心网友 时间:2023-10-11 13:43
test.php
<?php
$image = imagecreatefromjpeg("photo.jpg");
$copy = PIPHP_ImageCrop($image, 0, 0, 484, 160);
if (!$copy) echo "Crop failed: Argument(s) out of bounds";
else
{
imagejpeg($copy, "photo3.jpg");
echo "<img src='photo.jpg' align=left> ";
echo "Cropped at 100,0<br />with width / height";
echo "<br />of 110/140 pixels<br /><br />";
echo "<img src='photo3.jpg'>";
}
function PIPHP_ImageCrop($image, $x, $y, $w, $h)
{
$tw = imagesx($image);
$th = imagesy($image);
if ($x > $tw || $y > $th || $w > $tw || $h > $th)
return FALSE;
$temp = imagecreatetruecolor($w, $h);
imagecopyresampled($temp, $image, 0, 0, $x, $y,
$w, $h, $w, $h);
return $temp;
}
以上内容出自
《PHP快速开发工具箱--轻松解决PHP日常编程问题的100个插件工具》