Class: ImageProcessing::MiniMagick::Processor
- Defined in:
- lib/image_processing/mini_magick.rb
Defined Under Namespace
Modules: Utils
Constant Summary collapse
- SHARPEN_PARAMETERS =
{ radius: 0, sigma: 1 }
Class Method Summary collapse
- .load_image(path_or_magick, page: nil, geometry: nil, auto_orient: true, **options) ⇒ Object
- .save_image(magick, destination_path, allow_splitting: false, **options) ⇒ Object
Instance Method Summary collapse
- #append(*args) ⇒ Object
- #composite(overlay = :none, mask: nil, mode: nil, gravity: nil, offset: nil, args: nil, **options) {|magick| ... } ⇒ Object
- #define(options) ⇒ Object
- #limits(options) ⇒ Object
- #resize_and_pad(width, height, background: :transparent, gravity: "Center", **options) ⇒ Object
- #resize_to_fill(width, height, gravity: "Center", **options) ⇒ Object
- #resize_to_fit(width, height, **options) ⇒ Object
- #resize_to_limit(width, height, **options) ⇒ Object
- #rotate(degrees, background: nil) ⇒ Object
Methods inherited from Processor
accumulator, apply_operation, #custom, #initialize
Constructor Details
This class inherits a constructor from ImageProcessing::Processor
Class Method Details
.load_image(path_or_magick, page: nil, geometry: nil, auto_orient: true, **options) ⇒ Object
23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 |
# File 'lib/image_processing/mini_magick.rb', line 23 def self.load_image(path_or_magick, page: nil, geometry: nil, auto_orient: true, **) if path_or_magick.is_a?(::MiniMagick::Tool) magick = path_or_magick else source_path = path_or_magick magick = ::MiniMagick::Tool::Convert.new Utils.(magick, ) input_path = source_path input_path += "[#{page}]" if page input_path += "[#{geometry}]" if geometry magick << input_path end magick.auto_orient if auto_orient magick end |
.save_image(magick, destination_path, allow_splitting: false, **options) ⇒ Object
43 44 45 46 47 48 49 50 |
# File 'lib/image_processing/mini_magick.rb', line 43 def self.save_image(magick, destination_path, allow_splitting: false, **) Utils.(magick, ) magick << destination_path magick.call Utils.disallow_split_layers!(destination_path) unless allow_splitting end |
Instance Method Details
#append(*args) ⇒ Object
120 121 122 |
# File 'lib/image_processing/mini_magick.rb', line 120 def append(*args) magick.merge! args end |
#composite(overlay = :none, mask: nil, mode: nil, gravity: nil, offset: nil, args: nil, **options) {|magick| ... } ⇒ Object
79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 |
# File 'lib/image_processing/mini_magick.rb', line 79 def composite( = :none, mask: nil, mode: nil, gravity: nil, offset: nil, args: nil, **, &block) return magick.composite if == :none if .key?(:compose) warn "[IMAGE_PROCESSING] The :compose parameter in #composite has been renamed to :mode, the :compose alias will be removed in ImageProcessing 2." mode = [:compose] end if .key?(:geometry) warn "[IMAGE_PROCESSING] The :geometry parameter in #composite has been deprecated and will be removed in ImageProcessing 2. Use :offset instead, e.g. `geometry: \"+10+15\"` should be replaced with `offset: [10, 15]`." geometry = [:geometry] end geometry = "%+d%+d" % offset if offset = convert_to_path(, "overlay") mask_path = convert_to_path(mask, "mask") if mask magick << magick << mask_path if mask_path magick.compose(mode) if mode define(compose: { args: args }) if args magick.gravity(gravity) if gravity magick.geometry(geometry) if geometry yield magick if block_given? magick.composite end |
#define(options) ⇒ Object
110 111 112 113 |
# File 'lib/image_processing/mini_magick.rb', line 110 def define() return magick.define() if .is_a?(String) Utils.apply_define(magick, ) end |
#limits(options) ⇒ Object
115 116 117 118 |
# File 'lib/image_processing/mini_magick.rb', line 115 def limits() .each { |type, value| magick.args.unshift("-limit", type.to_s, value.to_s) } magick end |
#resize_and_pad(width, height, background: :transparent, gravity: "Center", **options) ⇒ Object
67 68 69 70 71 72 |
# File 'lib/image_processing/mini_magick.rb', line 67 def resize_and_pad(width, height, background: :transparent, gravity: "Center", **) thumbnail("#{width}x#{height}", **) magick.background color(background) magick.gravity gravity magick.extent "#{width}x#{height}" end |
#resize_to_fill(width, height, gravity: "Center", **options) ⇒ Object
60 61 62 63 64 65 |
# File 'lib/image_processing/mini_magick.rb', line 60 def resize_to_fill(width, height, gravity: "Center", **) thumbnail("#{width}x#{height}^", **) magick.gravity gravity magick.background color(:transparent) magick.extent "#{width}x#{height}" end |
#resize_to_fit(width, height, **options) ⇒ Object
56 57 58 |
# File 'lib/image_processing/mini_magick.rb', line 56 def resize_to_fit(width, height, **) thumbnail("#{width}x#{height}", **) end |
#resize_to_limit(width, height, **options) ⇒ Object
52 53 54 |
# File 'lib/image_processing/mini_magick.rb', line 52 def resize_to_limit(width, height, **) thumbnail("#{width}x#{height}>", **) end |
#rotate(degrees, background: nil) ⇒ Object
74 75 76 77 |
# File 'lib/image_processing/mini_magick.rb', line 74 def rotate(degrees, background: nil) magick.background color(background) if background magick.rotate(degrees) end |