在Php dev服务器win 10上更改权限或更改imagick的tmp目录



我正在运行symfony dev服务器的windows 10 pc上开发php7.1应用程序,但每次我运行脚本将svg转换为png时,我都会收到这个错误。

WriteBlob失败`/tmp/5f49ac095abe6.png'@error/png.c/MagickPNGErrorHandler/1630

我刚买了这台电脑,脚本可以在我的旧windows笔记本电脑上运行。我做了研究,怀疑这是一个权限问题,但我用尽了一切手段来更改php和imagick tmp存储位置。

如果这确实是一个权限问题,那么我如何更新php/imagick保存tmp文件的位置。

以下是我的整个方法供参考:

private function createImageFromSVG(ConfigLogo $logoConfig)
{
$svg = $logoConfig->getDefaultImage()->getContent();
$idColorArray = [
'first' => $logoConfig->getFirstColor(),
'second' => $logoConfig->getSecondColor(),
'third' => $logoConfig->getThirdColor(),
];
foreach ($idColorArray as $state => $color) {
if ($color != 'FFFFFF') {
$svg = preg_replace(
'/class="' . $state . '" style="fill:#([0-9a-fA-F]{6})/',
'class="' . $state . '" style="fill:#' . $color,
$svg
);
}
}
$fileName = sprintf('%s.png', uniqid());
$filePath = sprintf('/tmp/%s', $fileName);
$this->filePath = $filePath;
$im = new Imagick();
$im->setBackgroundColor(new ImagickPixel('transparent'));
$im->readImageBlob($svg);
$im->setImageFormat("png24");
$im->writeImage($filePath);  //error !
$file = new UploadedFile($filePath, $fileName .'.png');
$im->clear();
$im->destroy();
$oldImages  = $logoConfig->getRenderedLogoImages();
foreach ($oldImages as $image) {
if ($image->getImageName() !== 'default_logo.png') {
$this->uploadHandler->remove($image, 'imageFile');
}
$logoConfig->removeRenderedLogoImage($image);
}
$renderedImage = new ConfigLogoDefaultImage();
$renderedImage->setImageFile($file);
$renderedImage->setImageName($fileName);
$logoConfig->addRenderedLogoImage($renderedImage);
$this->operateImage($logoConfig, 'RenderedLogo');
}

错误发生在线路$im->writeImage($filePath)

提前感谢您的帮助。

无论谁可能面临这个问题,在我在C:/tmp创建tmp目录后,它就得到了解决。显然,imagick没有使用系统属性或php.ini中设置的systems-tmp目录

最新更新