Php 裁剪图像,保存它
我只想裁剪一下旧图像,然后再保存一次。发生了什么?谢谢Php 裁剪图像,保存它,php,gd,Php,Gd,我只想裁剪一下旧图像,然后再保存一次。发生了什么?谢谢 编辑:图像只是没有创建。它会创建空图像。为什么不使用更简单的: $filename = '/home/hey/Desktop/images/oldImage.jpg'; $percent = 0.5; // Get new dimensions list($width, $height) = getimagesize($filename); $new_width = $width * $percen
编辑:图像只是没有创建。它会创建空图像。为什么不使用更简单的:
$filename = '/home/hey/Desktop/images/oldImage.jpg';
$percent = 0.5;
// Get new dimensions
list($width, $height) = getimagesize($filename);
$new_width = $width * $percent;
$new_height = $height * $percent;
// Resample
$image_p = imagecreatetruecolor($new_width, $new_height);
$image = imagecreatefromjpeg($filename);
imagecopyresampled($image_p, $image, 0, 0, 0, 0, $new_width, $new_height, $width, $height);
file_put_contents("/home/hey/Desktop/images/oldImage.jpg", imagejpeg($image_p));
你为什么不告诉我们出了什么问题,也许我们可以帮你解决。图像是否未创建?这张照片看起来奇怪吗?它会变成一张猫的照片吗?你有什么错误?哦,对不起。我现在将更新。您是否阅读了
imagejpeg()
上的手册?这会让事情更清楚。这不仅更简单,也是实现这一点的唯一方法:)
// Save the image as 'simpletext.jpg'
imagejpeg($image_p, 'simpletext.jpg');