Note that there are some explanatory texts on larger screens.

plurals
  1. POWhy won't Carrierwave and MiniMagick images composite correctly?
    text
    copied!<p>I am using carrierwave (0.9.0) with fog (1.18.0), mini_magick (3.6.0), and Rackspace CloudFiles. I want to composite images.</p> <p>I have two models: Products and Emails. In the products uploader I am trying to create a process that loops through all the emails and composites the product image on top of each <code>email.background_image</code>. I also want to control the name of this image so that is:</p> <pre class="lang-rb prettyprint-override"><code>"#{email.name}_#{product.product_number}.jpg" </code></pre> <p>I have included my process and method below. Test result in a file being uploaded to cloudfiles named "email_123.png" and the original image. The name doesn't currently include the email's name and images are not compositing, I just receive the original back. Anything obvious I am missing here? Thanks!</p> <pre class="lang-rb prettyprint-override"><code>version :email do process :email_composite def email_composite Email.all.each do |email| email_image = email.secondary.url email_name = email.name merge(email_name, email_image) end end def merge(email_name, email_image) manipulate! do |img| @product = Product.find(model.id) email_image = ::MiniMagick::Image.open(email_image) img = email_image.composite(img, "jpg") do |c| c.gravity "Center" end # img = yield(img) if block_given? img = img.name "#{email_name}_#{@product.product_number}.png" img end end end </code></pre> <h1>UPDATED</h1> <p>First I wanted to thank you for your thorough answer, the amount of effort involved is obvious and appreciated.</p> <p>I had a few more questions when trying to implement this solution. Inside the #compose method you have:</p> <pre><code>email_image = ::MiniMagick::Image.open(email_image) </code></pre> <p>Should this be:</p> <pre><code>email_image = ::MiniMagick::Image.open(email_image_url) </code></pre> <p>I assume this from seeing the define_method call included below ( which was awesome by the way - I didn't know you could do that):</p> <pre><code>define_method(:email_image_url) { email.secondary.url } </code></pre> <p>After getting Undefined method "versions_for" I switched the #versions_for method as I will always want all email to have a secondary version.</p> <h2>versions_for before</h2> <pre><code>def self.versions_for emails reset_versions! email.find_each { |e| version_for_email(e) } end </code></pre> <h2>versions_for after changes</h2> <pre><code>def self.versions_for reset_versions! Email.all.find_each { |e| version_for_email(e) } end </code></pre> <p>This change allowed me get rid of the error. </p> <p>The end result of all of this is that everything appears as if it works, I can upload imagery without error, but now I have no resulting image for the emails versions. I still get my other versions like thumb etc. Any idea what could cause this? Again thanks for all the help you have provided thus far.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload