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



182
183
184
185
186
187
188
189
190
191
192
193
194
# File 'lib/image_processing/mini_magick.rb', line 182

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



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

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



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

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