【发布时间】:2016-05-21 04:43:07
【问题描述】:
我正在使用 Jcrop 来裁剪用户的图像。我在这里按照教程进行操作:http://deepliquid.com/content/Jcrop_Implementation_Theory.html。这是我的代码
private function resizeImage($file_info)
{
$dst_w = $dst_h = 150;
$jpeg_quality = 90;
$src = realpath($file_info['directory'] . '/' . $file_info['name']);
// CHMOD before cropping
chmod($src, 0777);
switch (strtolower($file_info['mime'])) {
case 'image/jpeg':
$src_img = imagecreatefromjpeg($src);
break;
case 'image/png':
$src_img = imagecreatefrompng($src);
break;
case 'image/gif':
$src_img = imagecreatefromgif($src);
break;
default:
exit('Unsupported type: ' . $file_info['mime']);
}
$dst_img = imagecreatetruecolor($dst_w, $dst_h);
// Resize and crop the image
imagecopyresampled(
$dst_img, $src_img, // Destination and Source image link resource
0, 0, // Coordinate of destination point
$this->crop['x'], $this->crop['y'], // Coordinate of source point
$dst_w, $dst_h, // Destination width and height
$this->crop['w'], $this->crop['h'] // Source width and height
);
// Output the image
switch (strtolower($file_info['mime'])) {
case 'image/jpeg':
imagejpeg($dst_img, null, $jpeg_quality);
break;
case 'image/png':
imagepng($dst_img);
break;
case 'image/gif':
imagegif($dst_img);
break;
default:
exit('Unsupported type: ' . $file_info['mime']);
}
}
我已经检查了目录和文件都是可写的(0777 权限)。我使用的所有变量也都定义明确,没有错误。但是,最终的图像仍然是原始形式,没有被裁剪。
有人知道为什么它不起作用吗?任何帮助表示赞赏。
【问题讨论】: