2
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

rubyで証明写真を加工する

Last updated at Posted at 2019-06-11

方法

ライブラリー等のインストール

$ brew install imagemagick
$ gem install mini_magick

画像処理

require "mini_magick"
image = MiniMagick::Image.open("./image.jpg")

# 回転と切り取りを同じ処理プロセスの中に囲む
image.combine_options do |img|
  img.auto_orient # 画像の向きをEXIF情報を
  img.strip # EXIF情報の除去
  img.density(300) # DPIを300にする
  img.gravity(:center) # 画像の切り取り重心を中央に置く
  # width = 30mm, height = 40mm として切り取り開始
  img.crop("#{30 * 2.83 * 300}x#{40 * 2.83 * 300}+0+0!")
end

# `./output.jpg` に書き込む
image.write("./output.jpg")

結果

入力画像

image.jpg

出力画像

output.jpg

参考

https://qiita.com/NaokiIshimura/items/a71cc118774e06d418c4
https://qiita.com/goyachanpuru/items/5939dbc1637e5ea4be74
https://morizyun.github.io/blog/minimagick-square-thumbnail-ruby/index.html

2
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
2
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?