Set PHP ImageMagick tmp directory

I am trying to set the temporary directory used by ImageMagick to convert files. Currently, when converting large PDF files, the temporary folder quickly reaches 2 or 3 terabytes. It is too much to store servers on disk, so I plan to use AWS EFS to store everything. I have an EFS drive installed in /efsand am trying to use it for a temporary path.

How can I install this in ImageMagick? I tried the following:

  • Setting PHP temp upload folder in php.ini - it debugs files and does not work
  • Modifying the ImagickMagick config.xml file that does not work.
  • Adding an environment variable MAGICK_TMPDIR=/efs
  • Adding an environment variable MAGICK_TEMPORARY_PATH=/efs

No matter what I do, it is always converted to a folder /tmp. How can I install this?

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

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

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

$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 several days!

Ubuntu Server

+4
source share
1 answer

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

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

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

Source: https://habr.com/ru/post/1662284/


All Articles