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.
How can I set this in ImageMagick? I have tried the following:
MAGICK_TMPDIR=/efs
MAGICK_TEMPORARY_PATH=/efs
No matter what I do, it always does the conversion in /tmp
folder. How can I set this?
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
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 server.
Imagick has a "setRegistry" method. http://php.net/manual/en/imagick.setregistry.php
You can use it to set the imagemagick temp path like so:
$i = new Imagick();
$i->setRegistry('temporary-path', '/efs');
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With