Skip to content

Commit

Permalink
i876 - Make memory, map, and disk limits in im_identify configurable
Browse files Browse the repository at this point in the history
- Added environment variable support for ImageMagick memory, map, and disk limits in the `im_identify` method
- Falls back to imagemagick-6-policy.xml defaults if no configuration is provided
- Improves flexibility and control over resource usage during image processing
  • Loading branch information
Shana Moore committed Nov 7, 2024
1 parent 9c4783a commit 73ac600
Showing 1 changed file with 12 additions and 1 deletion.
13 changes: 12 additions & 1 deletion lib/iiif_print/image_tool.rb
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,18 @@ def im_identify_geometry(lines)

# @return [Array<String>] lines of output from imagemagick `identify`
def im_identify
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}"
memory_limit = ENV["IM_MEMORY_LIMIT"]
map_limit = ENV["IM_MAP_LIMIT"]
disk_limit = ENV["IM_DISK_LIMIT"]

cmd = "identify"

cmd += " -limit memory #{memory_limit}" if memory_limit.present?
cmd += " -limit map #{map_limit}" if map_limit.present?
cmd += " -limit disk #{disk_limit}" if disk_limit.present?

cmd += " -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}"
Expand Down

0 comments on commit 73ac600

Please sign in to comment.