Module: ImageProcessing::MiniMagick::Processor::Utils

Defined in:
lib/image_processing/mini_magick.rb

Class Method Summary collapse

Class Method Details

.apply_define(magick, options) ⇒ Object



171
172
173
174
175
176
177
178
179
180
181
182
183
# File 'lib/image_processing/mini_magick.rb', line 171

def apply_define(magick, options)
  options.each do |namespace, settings|
    namespace = namespace.to_s.gsub("_", "-")

    settings.each do |key, value|
      key = key.to_s.gsub("_", "-")

      magick.define "#{namespace}:#{key}=#{value}"
    end
  end

  magick
end

.apply_options(magick, define: {}, **options) ⇒ Object



159
160
161
162
163
164
165
166
167
168
169
# File 'lib/image_processing/mini_magick.rb', line 159

def apply_options(magick, define: {}, **options)
  options.each do |option, value|
    case value
    when true, nil then magick.send(option)
    when false     then magick.send(option).+
    else                magick.send(option, *value)
    end
  end

  apply_define(magick, define)
end

.disallow_split_layers!(destination_path) ⇒ Object



150
151
152
153
154
155
156
157
# File 'lib/image_processing/mini_magick.rb', line 150

def disallow_split_layers!(destination_path)
  layers = Dir[destination_path.sub(/\.\w+$/, '-*\0')]

  if layers.any?
    layers.each { |path| File.delete(path) }
    raise Error, "Multi-layer image is being converted into a single-layer format. You should either process individual layers or set :allow_splitting to true. See https://github.com/janko-m/image_processing/wiki/Splitting-a-PDF-into-multiple-images for how to process each layer individually."
  end
end