class Libis::Format::Converter::ImageConverter
noinspection RubyTooManyInstanceVariablesInspection
Public Class Methods
input_types()
click to toggle source
# File lib/libis/format/converter/image_converter.rb, line 24 def self.input_types [:TIFF, :JPG, :PNG, :BMP, :GIF, :PDF, :JP2, :PBM, :PGM, :PPM] end
multipage?(format)
click to toggle source
# File lib/libis/format/converter/image_converter.rb, line 33 def self.multipage?(format) [:PDF, :TIFF, :GIF, :PBM, :PGM, :PPM].include?(format) end
new()
click to toggle source
Calls superclass method
Libis::Format::Converter::Base::new
# File lib/libis/format/converter/image_converter.rb, line 37 def initialize @wm_image = nil super end
output_types(format = nil)
click to toggle source
# File lib/libis/format/converter/image_converter.rb, line 28 def self.output_types(format = nil) return [] unless input_types.include?(format) if format [:TIFF, :JPG, :PNG, :BMP, :GIF, :PDF, :JP2] end
Public Instance Methods
colorspace(value)
click to toggle source
# File lib/libis/format/converter/image_converter.rb, line 86 def colorspace(value) @options[:colorspace] = value self end
convert(source, target, format, opts = {})
click to toggle source
Calls superclass method
Libis::Format::Converter::Base#convert
# File lib/libis/format/converter/image_converter.rb, line 101 def convert(source, target, format, opts = {}) super FileUtils.mkpath(File.dirname(target)) convert_image(source, target, format) target end
delete_date(value = true)
click to toggle source
# File lib/libis/format/converter/image_converter.rb, line 91 def delete_date(value = true) @delete_date = value self end
dpi(value)
click to toggle source
# File lib/libis/format/converter/image_converter.rb, line 71 def dpi(value) @options[:density] = value self end
flatten(value = true)
click to toggle source
# File lib/libis/format/converter/image_converter.rb, line 81 def flatten(value = true) @options[:flatten] = value self end
image_convert(_)
click to toggle source
# File lib/libis/format/converter/image_converter.rb, line 42 def image_convert(_) #force usage of this converter end
page(nr)
click to toggle source
# File lib/libis/format/converter/image_converter.rb, line 51 def page(nr) @page = nr self end
profile(icc)
click to toggle source
# File lib/libis/format/converter/image_converter.rb, line 96 def profile(icc) @profile = icc self end
quality(value)
click to toggle source
# File lib/libis/format/converter/image_converter.rb, line 66 def quality(value) @options[:quality] = value self end
quiet(v)
click to toggle source
# File lib/libis/format/converter/image_converter.rb, line 46 def quiet(v) @quiet = !!v self end
resample(value)
click to toggle source
# File lib/libis/format/converter/image_converter.rb, line 76 def resample(value) @options[:resample] = value self end
resize(geometry)
click to toggle source
# File lib/libis/format/converter/image_converter.rb, line 61 def resize(geometry) @options[:resize] = geometry self end
scale(percent)
click to toggle source
# File lib/libis/format/converter/image_converter.rb, line 56 def scale(percent) @options[:scale] = percent self end
Protected Instance Methods
convert_image(source, target, format)
click to toggle source
# File lib/libis/format/converter/image_converter.rb, line 114 def convert_image(source, target, format) if @page image = MiniMagick::Image.open(source) { |b| b.quiet } source = image.pages[@page].path if image.pages.size > 1 end MiniMagick::Tool::Convert.new do |convert| convert.quiet if @quiet convert << source convert.flatten if @options[:flatten].nil? && format == :JPG @flags.each {|f, v| v.is_a?(TrueClass) ? convert.send(f).+ : convert.send(f)} if @delete_date convert << '+set' << 'modify-date' << '+set' << 'create-date' end colorspace = @options.delete(:colorspace) || 'sRGB' unless @options.empty? convert.colorspace('RGB') @options.each {|o, v| convert.send(o, v.to_s)} end convert.colorspace(colorspace) convert.profile @profile if @profile convert.format(format) convert << target debug "ImageMagick command: '#{convert.command.join(' ')}'" end target end