【发布时间】:2012-11-17 05:27:56
【问题描述】:
我有以下 PHP 代码:
$w = 300; // Width of new image
$h = 300; // Height of new image
$oh = 540; // Original file height
$ow = 720; // Original file width
$x = 196;
$y = 50;
$image = imagecreatefromjpeg('fileToCrop.jpg');
$cropped_image = imagecreatetruecolor($w, $h);
imagecopyresampled($cropped_image, $image, 0, 0, $x, $y, $ow, $oh, $w, $h);
imagejpeg($cropped_image, 'fileToCrop.jpg', 100);
想要裁剪图像,但我的图像扭曲/高于原始图像,例如:
原文:
裁剪(显示“N”代表“Not”):
我看不出我的代码有什么问题,而且图像发生的事情变大了..
【问题讨论】:
-
原始尺寸为 720x540。使用以下函数获取高度/宽度。 php.net/manual/en/function.getimagesize.php
-
@twodayslate 抱歉,打错字了。
标签: php image gd crop image-resizing