Skip to content

Commit

Permalink
Merge pull request #375 from scientist-softserv/i867-make-imagemagick…
Browse files Browse the repository at this point in the history
…-limits-configurable

i876 - Make memory, map, and disk limits in `im_identify` configurable
  • Loading branch information
orangewolf authored Nov 7, 2024
2 parents 9c4783a + bda3097 commit fd975d6
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 1 deletion.
6 changes: 6 additions & 0 deletions lib/iiif_print/configuration.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,12 @@ class Configuration
attr_writer :after_create_fileset_handler

attr_writer :ingest_queue_name

# Example settings in the initializer:
# config.memory_limit = "512MiB" # Limit for memory usage
# config.map_limit = "1GiB" # Limit for map usage
# config.disk_limit = "20KP" # Limit for disk usage
attr_accessor :memory_limit, :map_limit, :disk_limit
##
# @return [Symbol, Proc]
def ingest_queue_name
Expand Down
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 = IiifPrint.config.memory_limit
map_limit = IiifPrint.config.map_limit
disk_limit = IiifPrint.config.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 fd975d6

Please sign in to comment.