3

I am using Amazon's S3 for image storage with carrierwave and fog configured. The images seem to store correctly however when I have a 'portrait' image (smaller width than height) it is not displaying correctly, but rather rotating the image on its side.

Any pointers in the right direction would be much appreciated!

uploaders/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
pjabbour
  • 31
  • 4

2 Answers2

1

in the uploader.rb file, try

process :auto_orient 

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

it should fix it.

user3623363
  • 101
  • 6
  • This solution does fix it for new uploads. I'm still looking for a solution for previous uploads, though I'm not sure I'll find one. – Justin Thiele Apr 01 '18 at 00:08
0

Perhaps instead of trying to resize_to_limit, instead create a version that you would like to conform to. For example, if you wanted all pictures to "intelligently" downsize to a square, you could do something like this

remove from uploader:

process :resize_to_limit => [420, 0]

add to uploader:

version :portrait do process :resize_to_fit => [100, 100] end

this way, carrierwave will store the original image, and will then also respond to your call when you do something like this:

@idea.image_url(:portrait)

this is assuming that your Idea model mounts your ImageUploader and has all the other necessary stuff already configured.

derekyau
  • 2,936
  • 1
  • 15
  • 14