I cannot get this CarrierWave uploader to process the image and resize how I would like.
The image is initially created with this.
class Screenshot
include Sidekiq::Worker
def perform(link_id)
link = Link.find(link_id)
file = Tempfile.new(["template_#{link.id.to_s}", '.jpg'], 'tmp', :encoding => 'ascii-8bit')
file.write(IMGKit.new(link.given_url, #quality: 50, width: 300).to_img(:jpg))
:quality => 50,
:width => 300,
:height => 300,
"crop-w" => 300,
"crop-h" => 300,
"disable-smart-width" => true,
"zoom" => 0.35).to_img(:jpg))
file.flush
link.snapshot = file
link.save
file.unlink
end
end
I could not get that working, so I thought I'll just resize in the uploader. Then I modified the uploader to do that as per this:
class SnapshotUploader < CarrierWave::Uploader::Base
include CarrierWave::MiniMagick
storage :file
storage :fog
process :convert_it
def convert_it
manipulate! do |img|
img.resize '300x300'
img
end
end
def convert_it2
resize_to_limit [300,300]
end
def convert_it3
resize_to_fit [300,-1]
end
def store_dir
"uploads/#{model.class.to_s.underscore}/#{mounted_as}/#{model.id}"
end
def cache_dir
"#{Rails.root}/tmp/uploads"
end
end
And that doesn't work either. I've tried each of the convert it methods, along with just a direct
process :resize_to_limit [300,300]
The image is created. Seems to be now always at 600 width by whatever height.
The image is uploaded to AWS S3.
I have Imagemagick installed with the --disable-openmp from homebrew. I can run mogrify and convert from the command line.
I can resize an image and save it in rails console with MiniMagick without issue.
I have made sure CarrierWave initializer has config.enable_processing = true.
I dont see any error messages in the console, or the sidekiq terminal window.
I'm new at this so I'm stumped at what else to try. Why is my image not resizing to the dimensions I've asked?
EDIT: The 600 widths were coming from IMGKit which means I have still never had carrierwave actually process the image.