Skip to content

Instantly share code, notes, and snippets.

@haywoood
Created January 18, 2013 19:19
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save haywoood/4567494 to your computer and use it in GitHub Desktop.
Save haywoood/4567494 to your computer and use it in GitHub Desktop.
class FileUploader < CarrierWave::Uploader::Base
require 'carrierwave/processing/mini_magick'
include CarrierWave::MiniMagick
storage :fog
version :thumb do
process :resize_first_page
process :convert => :jpg
process :set_content_type
end
private
def resize_first_page
manipulate! do |pdff|
first_page = Magick::ImageList.new("#{current_path}[0]").first
thumb = first_page.resize_to_fill!(220,155)
thumb
end
end
def set_content_type(*args)
self.file.instance_variable_set(:@content_type, "image/jpg")
end
end
@atstockland
Copy link

Even 3 years old this seems to be a valid way to convert a PDF cover page. However, Magick::ImageList.new results in the error uninitialized constant Magick::ImageList. Are you aware if anything has changed with MiniMagick that makes this method no longer available? Thanks!

@sighmin
Copy link

sighmin commented Jul 11, 2016

@atstockland I'm getting a maybe it is not an image? error when it enters manipulate!, did you experience this at all?

@itkin
Copy link

itkin commented Dec 2, 2016

+1 @sighmin did you find a workaround ?

@iamameme
Copy link

ImageList in MiniMagick was removed. It was in beta and the developer concluded that it wasted too much memory to be included sadly :/

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment