17
13

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.

carriewaveでExifの回転情報(rotation)をよしなに修正した後 Exif情報を除去する

Last updated at Posted at 2015-12-17

Exifの回転情報をよしなにした後 Exif情報を除去するメソッドを書いてみた。

回転情報をよしなにExif情報除去を別々のメソッドにすると(manipulate!をそれぞれで呼び出すと)、画像ファイルのオープンとRMagick/MiniMagick等のオブジェクト生成処理もそれぞれで発生するので纏めたメソッドにする方が良いかと。。

app/uploaders/image_uploader.rb
class ImageUploader < CarrierWave::Uploader::Base
  include CarrierWave::MiniMagick

  # Exif情報のOrientationから画像をよしなに修正した後、Exif情報を除去する
  process :fix_exif_rotation_and_strip_exif

  def fix_exif_rotation_and_strip_exif
    manipulate! do |img|
      img.auto_orient # よしなに!
      img.strip       # Exif情報除去
      img = yield(img) if block_given?
      img
    end
  end
end
17
13
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
17
13

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?