Solution for large /tmp/magick-xxx files created by ImageMagick and policy.xml configuration changes

Tadashi Shigeoka ·  Thu, March 1, 2018

I’ll introduce the solution for when large files named /tmp/magick-xxx are created on servers using ImageMagick, and configuration changes to policy.xml.

ImageMagick | イメージマジック

Prerequisites

I was using ImageMagick on an image processing server built with ngx_small_light, when suddenly disk warnings and alerts started occurring.

Steps to check and delete /tmp/magick-xxx files

First, check disk free space with the df command. It was at 97% with only 290MB remaining…

$ df -h
Filesystem      Size  Used Avail Use% Mounted on
/dev/xvda1      7.8G  7.4G  290M  97% /
devtmpfs        3.6G   20K  3.6G   1% /dev
tmpfs           3.6G     0  3.6G   0% /dev/shm

Confirm that there are tmp files output by ImageMagick in the /tmp directory.

$ ls -lh /tmp/
total 2.0G
-rw------- 1 nginx    nginx    2.0G Mar  3 06:56 magick-9162ZVLalRUJc16h

Delete them without question.

$ sudo rm /tmp/magick-9162ZVLalRUJc16h

ImageMagick configuration changes

When I checked ImageMagick’s configuration values, Disk: unlimited was set.

$ identify -list resource
Resource limits:
  Width: 214.7MP
  Height: 214.7MP
  Area: 15.31GP
  Memory: 7.1292GiB
  Map: 14.258GiB
  Disk: unlimited
  File: 768
  Thread: 4
  Throttle: 0
  Time: unlimited

I modified /usr/local/etc/ImageMagick-6/policy.xml as follows:


  
  
   

After modifying policy.xml, you can immediately confirm that the settings are reflected using the identify -list resource command.

$ identify -list resource              
Resource limits:
  Width: 214.7MP
  Height: 214.7MP
  Area: 15.31GP
  Memory: 7.1292GiB
  Map: 0B
  Disk: 0B
  File: 768
  Thread: 1
  Throttle: 0
  Time: unlimited

That’s all from the Gemba where I was troubled by large tmp files output by ImageMagick.

References