Last active
October 26, 2015 06:48
-
-
Save NARKOZ/4294977 to your computer and use it in GitHub Desktop.
ImageMagick vs GraphicsMagick (Resizing to Fill a Given Space)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# gem 'mini_magick' 5217dfe | |
# GraphicsMagick 1.3.17 | |
# ImageMagick 6.7.0-10 | |
# Resize to fill (old method) | |
# http://www.imagemagick.org/Usage/resize/#space_fill | |
# | |
# works with ImageMagick as expected | |
# fails to work with GraphicsMagick as expected | |
def resize_to_fill(width, height) | |
manipulate! do |img| | |
img.combine_options do |cmd| | |
cmd.resize "#{width*2}x" | |
cmd.resize "x#{width*2}<" | |
cmd.resize '50%' | |
cmd.gravity 'center' | |
cmd.crop "#{width}x#{height}+0+0" | |
cmd.repage.+ | |
end | |
img | |
end | |
end | |
# Resize to fill (new method, with '^' flag) | |
# http://www.imagemagick.org/Usage/resize/#fill | |
# | |
# works both with ImageMagick and GraphicsMagick as expected | |
def resize_to_fill(width, height) | |
manipulate! do |img| | |
img.combine_options do |cmd| | |
cmd.resize "#{width}x#{height}^" | |
cmd.gravity 'center' | |
cmd.extent "#{width}x#{height}" | |
end | |
img | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-gravity
option was removed from GraphicsMagick'smogrify
command.minimagick/minimagick#264 (comment)