Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Carrierwave resize is not working (Rails 3 and MiniMagick)

what I want to do is to save a website url with a full-size snapshot via IMGKit. In one of the views I also want to have a thumbnail version of the snapshot. I'm using carrierwave in order to associate the snapshot with the object an MiniMagick to manipulate it, the problem is that it generates the 'thumbnail' image but doesn't resize it so as a result, I have two full-size snapshots, one of then with 'thumb' as prefix.

I have this model in rails

class Webpage
  mount_uploader :snapshot, SnapshotUploader
  field :url, type: String
  field :title, type: String

  after_create :get_snapshot

  private
  def get_snapshot
    file = Tempfile.new(["#{id}#{title}".downcase, '.jpg'], 'tmp', :encoding => 'ascii-8bit')
    image = IMGKit.new(url, quality: 90).to_jpg
    file.write(image)
    file.flush
    self.snapshot= file
    self.save
    file.unlink
  end


end

And I have this in the Uploader in order to create the thumbnail version:

class SnapshotUploader < CarrierWave::Uploader::Base
  include CarrierWave::MiniMagick

  version :thumb do
    process resize_to_fill: [180, 180]
  end

end

Using the console I tried MiniMagick for resizing an image and it works fine son I don't know what is happening. I'm not sure if I'm doing it right so any help would be appreciated. Thanks.

like image 761
John Avatar asked Nov 30 '22 05:11

John


1 Answers

OK, I'm stupid. I had an initializer with

config.enable_processing = false

so it will never process the image. Just setting it to true or deleting the line solved my problem.

like image 158
John Avatar answered Dec 09 '22 15:12

John