class Object
Constants
- ARGS
- PRESETS
Public Class Methods
new(asset, opts, args)
click to toggle source
@see github.com/minimagick/minimagick#usage – All but
the boolean @ options are provided by Minimagick.
# File lib/jekyll/assets/proxies/magick.rb, line 28 def initialize(asset, opts, args) @path = asset.filename @opts = opts @asset = asset @args = args end
Public Instance Methods
any_preset?(*keys)
click to toggle source
# File lib/jekyll/assets/proxies/magick.rb, line 67 def any_preset?(*keys) @opts.keys.any? do |key| keys.include?(key) end end
magick_crop(_, cmd)
click to toggle source
# File lib/jekyll/assets/proxies/magick.rb, line 120 def magick_crop(_, cmd) if @opts.key?(:crop) then cmd.crop @opts[:crop] end end
magick_flip(_, cmd)
click to toggle source
# File lib/jekyll/assets/proxies/magick.rb, line 111 def magick_flip(_, cmd) if @opts.key?(:flip) then cmd.flip @opts[:flip] end end
magick_gravity(_, cmd)
click to toggle source
# File lib/jekyll/assets/proxies/magick.rb, line 129 def magick_gravity(_, cmd) if @opts.key?(:gravity) then cmd.gravity @opts[:gravity] end end
magick_preset_resize(img, cmd)
click to toggle source
# File lib/jekyll/assets/proxies/magick.rb, line 147 def magick_preset_resize(img, cmd) return unless preset? width, height = img.width * 4, img.height * 4 if any_preset?(:"4x", :quadruple) width, height = img.width * 2, img.height * 2 if any_preset?(:"2x", :double) width, height = img.width / 2, img.height / 2 if any_preset?(:"1/2", :half) width, height = img.width / 3, img.height / 3 if any_preset?(:"1/3", :"one-third") width, height = img.width / 4, img.height / 4 if any_preset?(:"1/4", :"one-fourth") width, height = img.width / 3 * 2, img.height / 3 * 2 if any_preset?(:"2/3", :"two-thirds") width, height = img.width / 4 * 2, img.height / 4 * 2 if any_preset?(:"2/4", :"two-fourths") width, height = img.width / 4 * 3, img.height / 4 * 3 if any_preset?(:"3/4", :"three-fourths") cmd.resize "#{width}x#{height}" end
magick_quality(_, cmd)
click to toggle source
# File lib/jekyll/assets/proxies/magick.rb, line 83 def magick_quality(_, cmd) if @opts.key?(:quality) then cmd.quality @opts[:quality] end end
magick_resize(_, cmd)
click to toggle source
# File lib/jekyll/assets/proxies/magick.rb, line 92 def magick_resize(_, cmd) raise DoubleResizeError if @opts.key?(:resize) && preset? if @opts.key?(:resize) then cmd.resize @opts[:resize] end end
magick_rotate(_, cmd)
click to toggle source
# File lib/jekyll/assets/proxies/magick.rb, line 102 def magick_rotate(_, cmd) if @opts.key?(:rotate) then cmd.rotate @opts[:rotate] end end
preset?()
click to toggle source
# File lib/jekyll/assets/proxies/magick.rb, line 76 def preset? (@opts.keys - ARGS.map(&:to_sym)).any? end
process()
click to toggle source
# File lib/jekyll/assets/proxies/magick.rb, line 37 def process img = MiniMagick::Image.open(@path) methods = private_methods(true).select { |v| v.to_s.start_with?("magick_") } if img.respond_to?(:combine_options) then img.combine_options do |cmd| methods.each do |method| send( method, img, cmd ) end end else methods.each do |method| send( method, img, img ) end end img.write( @path ) ensure img.destroy! end