Imagemagickで画像変換時にキャッシュリソースが足りなくて転ける

Google Photoにheic形式でファイルをアップロードすると「高画質」(16MPに縮小される)設定でも縮小されないようなのでどのくらいのサイズまでOKなのかを試していたのですが,倍々で画像結合していたら128MPほどのファイル作成時に失敗しました.

$ convert -append out.heic out.heic out128.heic
convert-im6.q16: cache resources exhausted `out.heic' @ error/cache.c/OpenPixelCache/4083.

処理しているファイルは無駄にでかいです.

$ identify ./out.heic
./out.heic HEIC 9884x6552 9884x6552+0+0 8-bit YCbCr 0.020u 0:00.010

このあたりのページを参考にポリシーファイルを修正してメモリを増やしてみます.

$ sudo git -C /etc diff /etc/ImageMagick-6/policy.xml
diff --git a/ImageMagick-6/policy.xml b/ImageMagick-6/policy.xml
index 59d2fc6..4c6d088 100644
--- a/ImageMagick-6/policy.xml
+++ b/ImageMagick-6/policy.xml
@@ -57,8 +57,8 @@
   <!-- <policy domain="system" name="memory-map" value="anonymous"/> -->
   <!-- <policy domain="system" name="max-memory-request" value="256MiB"/> -->
   <!-- <policy domain="resource" name="temporary-path" value="/tmp"/> -->
-  <policy domain="resource" name="memory" value="256MiB"/>
-  <policy domain="resource" name="map" value="512MiB"/>
+  <policy domain="resource" name="memory" value="2048MiB"/>
+  <policy domain="resource" name="map" value="4096MiB"/>
   <policy domain="resource" name="width" value="16KP"/>
   <policy domain="resource" name="height" value="16KP"/>
   <!-- <policy domain="resource" name="list-length" value="128"/> -->

うまく行くようになりました :)

$ time convert -append out.heic out.heic out128.heic; echo $?

real    2m33.128s
user    6m42.527s
sys     0m4.704s
0
$ ls -l out128.heic
-rw-r--r-- 1 matoken matoken 4286359 Oct 20 00:30 out128.heic
$ identify out128.heic
out128.heic HEIC 9884x13104 9884x13104+0+0 8-bit YCbCr 0.000u 0:00.010

でも割り当て過ぎな気もするのでも少し減らそう.

$ dpkg-query -W imagemagick
imagemagick     8:6.9.10.23+dfsg-2.1+b2
$ lsb_release -dr
Description:    Debian GNU/Linux bullseye/sid
Release:        unstable
$ uname -m
x86_64

コメントを残す

メールアドレスが公開されることはありません。 が付いている欄は必須項目です

To respond on your own website, enter the URL of your response which should contain a link to this post's permalink URL. Your response will then appear (possibly after moderation) on this page. Want to update or remove your response? Update or delete your post and re-enter your post's URL again. (Find out more about Webmentions.)