From 28d5c7f15471044b76f813926005fc1a7c26683d Mon Sep 17 00:00:00 2001 From: Shana Moore Date: Wed, 6 Nov 2024 15:45:00 -0800 Subject: [PATCH] :bug: Fix image processing issue - add sync to convert method - Adjusted im_identify in image_tool to set specific resource constraints on memory, map, and disk, reducing risk of process termination. - This change addresses out-of-memory issues when processing high-resolution images in ValkyrieCreateDerivativesJob. --- lib/iiif_print/image_tool.rb | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/lib/iiif_print/image_tool.rb b/lib/iiif_print/image_tool.rb index 8d6df030..6e3c256c 100644 --- a/lib/iiif_print/image_tool.rb +++ b/lib/iiif_print/image_tool.rb @@ -41,7 +41,7 @@ def convert_image(source, destination, monochrome) monochrome &&= destination.slice(-4, 4).index('tif') mono_opts = "-depth 1 -monochrome -compress Group4 -type bilevel " opts = monochrome ? mono_opts : '' - cmd = "convert #{source} #{opts}#{destination}" + cmd = "convert #{source} #{opts}#{destination} && sync" `#{cmd}` end @@ -74,8 +74,11 @@ def im_identify_geometry(lines) # @return [Array] lines of output from imagemagick `identify` def im_identify - cmd = "identify -format 'Geometry: %G\nDepth: %[bit-depth]\nColorspace: %[colorspace]\nAlpha: %A\nMIME type: %m\n' #{path}" - `#{cmd}`.lines + cmd = "identify -limit memory 8GiB -limit map 16GiB -limit disk 50GiB -format 'Geometry: %G\nDepth: %[bit-depth]\nColorspace: %[colorspace]\nAlpha: %A\nMIME type: %m\n' #{path}" + output, status = Open3.capture2(cmd) + Rails.logger.info "Identify command output: #{output}" + Rails.logger.info "Identify command status: #{status}" + output.lines end def im_mime(lines)