LoginSignup
2
0

More than 5 years have passed since last update.

Piet::CarrierWaveExtensionによる画像最適化がSolarisで動かなかった件

Posted at

Piet::CarrierWaveExtensionを使い、jpeg画像の最適化を試みた所、開発に使っていたMacbook proでは問題無かったのですが、
solarisでは最適化されない現象が発生していました。

原因を調べていた所、
https://github.com/albertbellonch/piet/blob/master/lib/piet.rb

piet.rbの25行目

lib/piet.rb
    def mimetype(path)
      IO.popen(['file', '--brief', '--mime-type', path], in: :close, err: :close){|io| io.read.chomp.sub(/image\//, '')}
    end

こちらで、fileコマンドで識別している所が原因でした。
solarisのfileコマンドだと--briefも--mime-typeも存在しません。

その為、solarisでも使えるmimeの識別方が必要だったので、ちょうど該当プロジェクトではshared-mime-infoを使っていました。
ですので以下の様なモジュールを作り、Uploader側で、このmoduleをincludeする事で対応しました。

piet_uploader.rb
require "shared-mime-info"
module PietUploader
  include Piet::CarrierWaveExtension
  def Piet.mimetype(path)
    MIME.check(path).sub_type
  end 
end
2
0
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
0