2013-10-03 44 views
3

我正在使用亞馬遜的S3進行配置了carrierwave和fog的圖像存儲。這些圖像似乎可以正確存儲,但是當我有一幅「肖像」圖像(寬度小於高度)時,圖像顯示不正確,而是旋轉圖像。Rails image_tag旋轉圖像

任何指針正確的方向將不勝感激!

上傳/ image_uploader.rb

class ImageUploader < CarrierWave::Uploader::Base 
    include CarrierWave::RMagick 

    include Sprockets::Helpers::RailsHelper 
    include Sprockets::Helpers::IsolatedHelper 

    storage :fog 

    include CarrierWave::MimeTypes 
    process :set_content_type 

    process :resize_to_limit => [420, 0] 

    def store_dir 
    "uploads/#{model.class.to_s.underscore}/#{mounted_as}/#{model.id}" 
    end 

    def extension_white_list 
    %w(jpg jpeg png) 
    end 

end 

show.html.haml

= image_tag(@idea.image_attachments.first.image.url).to_s 

image_attachment.rb

class ImageAttachment < ActiveRecord::Base 
    require 'carrierwave/orm/activerecord' 
    attr_accessible :image, :description 
    belongs_to :image_attachable, polymorphic: true 
    mount_uploader :image, ImageUploader 
end 
+1

這似乎是來自iPhone的圖像的問題,並且具有與它們相關聯的exif(方向)數據。 – pjabbour

+0

我有這個確切的問題,你找到一個解決方案? – pingu

回答

0

也許,而不是試圖resize_to_limit,而是創建一個版本你想遵守。例如,如果你想要的所有照片以「智能」縮減到一個廣場,你可以做這樣的事情

從上傳中刪除:

process :resize_to_limit => [420, 0] 

添加到上傳者:

版本:肖像做 過程:resize_to_fit => [100,100] 結束

這樣,carrierwave將存儲原始圖像,然後也會迴應你的電話,當你做這樣的事情:

@idea.image_url(:portrait) 

這是假設您的Idea模型掛載了您的ImageUploader並且已經配置了所有其他必需的東西。

在uploader.rb文件
0

,嘗試

process :auto_orient 

def auto_orient 
manipulate! do |image| 
    image.tap(&:auto_orient) 
end 
end 

它應該修復它。