Dynamic versions of carrier wave images

I have a list of sizes in the database, and I need to resize my images, and I use wavewave to load them.

Is there a way to use the carrier to handle resizing? I am now using the rake task to do this, although I will probably switch to using girl_friday members so that I can call it more easily.

Edit

In the end, I ended up without using the correct carrier versions, but used the carrier callback to add resize jobs to the background processor (in this case 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 
+4
source share
2 answers

I'm not sure if this will work, but I think you can dynamically add versions to your loader model.

I tried this method on my bootloader and was able to determine the new version for the bootloader 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, you can work with this method call in the hook of creating the db table, which makes a list of versions.

Just an idea, I would have experienced it hard before going to production.

+2
source

You need to call the class method 'version' from the 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 
+2
source

All Articles