Search code examples
ruby-on-railspngtransparencycarrierwave

Rails and Carrierwave - PNG not transparent in production


I'm using the Carrierwave gem on Rails. Somehow, PNG images keep their transparent background when uploaded in development, but not in production, where their background becomes white. Here are snippets of my code:

ImageUploader.rb

process resize_to_fit: [1000, 500]

version :thumb do
  process resize_and_pad: [315, 100, :transparent, 'Center']
end
version :category_thumb do
  process resize_and_pad: [160, 100, :transparent, 'Center']
end

In the view

<div class="container col-sm-12 center-block categories-section">
    <div class="row col-sm-12">
        <div class="group">
            <div class="categories-item categories-line"></div>
            <div class="categories-item categories-text text-center"><p><b style="font-size: 30px !important">Kategorien</b></p></div>
            <div class="categories-item categories-line"></div>
        </div>
    </div>
    <div class="row vertical-divider col-sm-12">
      <% @blog_categories.each do |bc| %>
          <div class="col-sm-4 col-lg-3 col-md-3">
              <%= link_to image_tag(bc.image.category_thumb.url), blog_category_blog_articles_path(bc.id) %>
          <p><%= bc.description %></p>
          </div>
      <% end %>
    </div>
</div>

I'm using Capistrano for deployment. Cheers in advance


Solution

  • Sounds like you might have different versions of ImageMagick running, and the production one might need an update.

    You can see what versions you have by SSH-ing in and running convert -version