I have a list of sizes in the database and I need to resize my images to, and I use carrierwave to upload them.
Is there some way to use carrierwave to handle the resizing? right now I'm using a rake task to do it, although I'll probably switch to using girl_friday actors so that I can more easily trigger it.
In the end I ended up without using proper carrierwave versions, but used a carrierwave callback to add the resizing jobs to the background processor (In this case it's girl_friday)
class ImageUploader < CarrierWave::Uploader::Base
after :store, :resize_by_db
def resize_by_db(args)
widths = Resolutions.all.map &:width
widths.each do |width|
RESIZE_QUEUE << {:source => path, :width => width}
end
end
end
You need to call class method 'version' from instance method.
process :selected_version
def selected_version
aspect_ratio = model.aspect_ratio
name = aspect_ratio.name
self.class.version name do
process :crop
process :resize_to_fit => [aspect_ratio.width, aspect_ratio.height]
end
end
I'm not sure if this will work but I think you can dynamically add versions to your uploader model.
I tried this method on my uploader and was able to define a new version on the uploader just by calling the method.
def self.defind_version(version_title, width, height)
version version_title do
process :resize_to_limit => [width, height]
end
end
So then you can work that method call into a create hook of the db table that makes the list of versions.
Just an idea, I would test heavily before going to production.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With