我正在使用carrierwave
作为我在Rails项目中上传图片的宝石,它可以在除Android以外的所有设备上正常工作,每当我从Android设备上传图像然后它旋转90度。
这些是用于上传图片的宝石:
gem 'rmagick'
gem 'carrierwave'
以下是avatar_uploader.rb
# encoding: utf-8
class AvatarUploader < CarrierWave::Uploader::Base
# Include RMagick or MiniMagick support:
include CarrierWave::RMagick
# include CarrierWave::MiniMagick
# Choose what kind of storage to use for this uploader:
storage :file
# storage :fog
def store_dir
"uploads/#{model.class.to_s.underscore}/#{mounted_as}/#{model.id}"
end
version :thumb, :if => :image? do
process :crop
resize_to_fill(100, 100)
end
version :large, :if => :image? do
resize_to_limit(600, 600)
end
def crop
if model.crop_x.present?
resize_to_limit(600, 600)
manipulate! do |img|
x = model.crop_x.to_i
y = model.crop_y.to_i
w = model.crop_w.to_i
h = model.crop_h.to_i
img.crop!(x, y, w, h)
end
end
end
protected
def image?(new_file)
new_file.content_type.include? 'image'
end
end
答案 0 :(得分:1)
最后我在这里得到了解决方案https://stackoverflow.com/a/18541893,
这是我为修复它所做的更改:
在avatar_uploader.rb
中添加了此内容:
def auto_orient
manipulate! do |img|
img = img.auto_orient
end
end
并将其用作:
version :thumb, :if => :image? do
process :auto_orient // here it is used
process :crop
resize_to_fill(100, 100)
end
version :large, :if => :image? do
process :auto_orient // here it is used
resize_to_limit(600, 600)
end
那就是:)