【发布时间】:2016-11-25 07:59:39
【问题描述】:
我正在使用 php Imagick 上传使用 `cropImage' 的裁剪图像,之后我想使用 'resizeImage' 调整裁剪图像的大小。此处图像裁剪工作正常,但调整图像大小显示异常,我的代码如下。
上传.php
move_uploaded_file($_FILES["file"]["tmp_name"], $newUploadDir. $newfilename);
cropImage($newUploadDir.$newfilename,$newUploadDirSmall.$newfilename,$x,$y,$w,$h);
resizeImage($newUploadDirSmall.$newfilename,$newUploadDirSm.$newfilename,211, 50, 0, 0, true, false);
MagikLib.php
<?php
function cropImage($source,$destination, $startX, $startY, $width, $height)
{
$imagick = new \Imagick(realpath($source));
$imagick->cropImage($width, $height, $startX, $startY);
header("Content-Type: image/jpg");
echo $imagick->getImageBlob();
$imagick->writeImage($destination);
}
function resizeImage($source,$destination, $width, $height, $filterType, $blur, $bestFit, $cropZoom)
{
//The blur factor where > 1 is blurry, < 1 is sharp.
$imagick = new \Imagick(realpath($source));
$imagick->resizeImage($width, $height, $filterType, $blur, $bestFit);
$cropWidth = $imagick->getImageWidth();
$cropHeight = $imagick->getImageHeight();
if ($cropZoom) {
$newWidth = $cropWidth / 2;
$newHeight = $cropHeight / 2;
$imagick->cropimage(
$newWidth,
$newHeight,
($cropWidth - $newWidth) / 2,
($cropHeight - $newHeight) / 2
);
$imagick->scaleimage(
$imagick->getImageWidth() * 4,
$imagick->getImageHeight() * 4
);
}
header("Content-Type: image/jpg");
$imagick->writeImage($destination);
}
?>
MagicLib.php 引用自 http://phpimagick.com/Imagick/cropImage 和 http://phpimagick.com/Imagick/resizeImage
cropImage 工作正常并将图像保存到文件夹但 resizeImage 显示以下错误
Warning: Cannot modify header information - headers already sent by (output started at /home/a/public_html/img/MagikLib.php:7) in /home/a/public_html/img/MagikLib.php on line 34
Fatal error: Uncaught exception 'ImagickException' with message 'unable to open image `/home/a/public_html/img/images//b6d767d2f8ed5d21a44b0e5886680cb9/user/sm/image1.jpg': No such file or directory @ error/blob.c/OpenBlob/2709' in /home/a/public_html/img/MagikLib.php:35 Stack trace: #0 /home/a/public_html/img/MagikLib.php(35): Imagick->writeimage('/home/a/pu...') #1 /home/a/public_html/img/upload1.php(74): resizeImage('/home/a/pu...', '/home/a/pu...', 211, 50, 0, 0, true, false) #2 {main} thrown in /home/a/public_html/img/MagikLib.php on line 35
如何解决这个问题?
【问题讨论】:
-
/home/a/public_html/img/images//b6d767d2f8ed5d21a44b0e5886680cb9/user/sm/ 这个目录是否存在并且www-data用户在这个路径上有x权限
-
pastebin.com/EBDjBRRk这是我的完整代码请看一次