gouf
7/7/2015 - 1:25 AM

Mini Magick で画像の任意の枠を切り抜き

Mini Magick で画像の任意の枠を切り抜き

Crop Image with Mini Magick

Dependencies

  • ImageMagick
  • Mini Magick

(ruby version: 2.2.2p95)

Install

sudo apt-get install imagemagick
gem install bundler
bundle init
echo "gem 'mini_magick'" >> Gemfile
bundle

Write short code

require 'bundler'
Bundler.require

def crop(image, w_offset, h_offset, w, h)

  # image.crop('104x193+98+95')
  image.crop("#{w_offset}x#{h_offset}+#{w}+#{h}")

  image
end

image = MiniMagick::Image.open(File.expand_path('./sample.jpg'))
crop(image, 104, 193, 98, 95).write(File.expand_path('./sample_cropped.jpg'))

Link