设置PHP ImageMagick tmp目录 [英] Set PHP ImageMagick tmp directory

查看:446
本文介绍了设置PHP ImageMagick tmp目录的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试设置ImageMagick用于转换文件的临时目录。目前,在转换大型PDF时,临时文件夹很快就会达到2或3太字节。这太过于无法容纳服务器磁盘,因此我计划使用AWS EFS来存储所有内容。我将EFS驱动器安装在 / efs ,并尝试将其用于临时路径。

I am trying to set the temporary directory that ImageMagick uses to convert files. Currently, when converting large PDFs, the temp folder quickly gets to 2 or 3 terabytes. This is too much to hold on the servers disk, so I plan to use an AWS EFS to store everything. I have the EFS drive mounted at /efs and am trying to use it for the temp path.

怎么能我在ImageMagick中设置了这个?我尝试过以下方法:

How can I set this in ImageMagick? I have tried the following:


  • 在php.ini中设置PHP的临时上传文件夹 - 这会破坏文件上传并且不合适

  • 更改ImagickMagick的config.xml文件,该文件不起作用。

  • 添加环境变量 MAGICK_TMPDIR = / efs

  • 添加环境变量 MAGICK_TEMPORARY_PATH = / efs

  • Setting PHP's temp upload folder in php.ini - this breaks file uploads and is no good
  • Changing ImagickMagick's config.xml file, which doesn't work.
  • Adding environment variable MAGICK_TMPDIR=/efs
  • Adding environment variable MAGICK_TEMPORARY_PATH=/efs

无论我做什么,它总是在 / tmp 文件夹中进行转换。我该如何设置?

No matter what I do, it always does the conversion in /tmp folder. How can I set this?

它是不同的,因为它是PHP?显然在命令行版本中你可以这样做:

Is it different because it is PHP? Apparently in the command line version you can do this:

convert -define registry:temporary-path=/Volumes/external/tmp

我当前的PHP代码是这样的,我想知道是否有一个函数在这里设置tmp目录?就像一个 $ imagick-> setTmpDir('/ efs')之类的东西。我搜索过PHP API,但找不到任何方法。

My current PHP code is this, I was wondering if there is a function to set the tmp dir here? Like a $imagick->setTmpDir('/efs') sort of thing. I have searched the PHP API and cannot find any way to do so.

$imagick = new Imagick();
$imagick->setResourceLimit( Imagick::RESOURCETYPE_MEMORY, 5 ); //Limit RAM and force script to convert using disk swap
$imagick->setResolution(600,600); //Set DPI to 600
$imagick->setCompressionQuality(100);
$imagick->readImageBlob($file); //Load the image
$imagick->deskewImage(40); //Deskew image
$imagick->setImageFormat('jpg'); //Set format
$imagick->writeImages(storage_path("app/docs/".$doc->id.".jpg"), false); //Save the converted image

有什么想法吗?我已经这样做了好几天了!

Any ideas? I have been doing this for days!

Ubuntu服务器。

Ubuntu server.

推荐答案

Imagick有一个setRegistry方法。 http://php.net/manual/en/imagick.setregistry.php

Imagick has a "setRegistry" method. http://php.net/manual/en/imagick.setregistry.php

您可以使用它来设置imagemagick临时路径,如下所示:

You can use it to set the imagemagick temp path like so:

$i = new Imagick();
$i->setRegistry('temporary-path', '/efs');

这篇关于设置PHP ImageMagick tmp目录的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆