gpt4 book ai didi

ruby-on-rails - Rails image_tag 旋转图像

转载 作者:行者123 更新时间:2023-12-02 03:42:36 25 4
gpt4 key购买 nike

我正在使用亚马逊的 S3 进行图像存储,并配置了载波和雾。这些图像似乎可以正确存储,但是当我有一个“肖像”图像(宽度小于高度)时,它没有正确显示,而是在其侧面旋转图像。

任何指向正确方向的指示都将不胜感激!

上传者/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

显示.html.haml

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

图片附件.rb

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

最佳答案

在uploader.rb文件中,尝试

process :auto_orient 

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

它应该修复它。

关于ruby-on-rails - Rails image_tag 旋转图像,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19165217/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com