Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

RMagick - ImageMagick gives error "no decode delegate for this image format"

The problem occurs when i try to manipulate an image uploaded from sinatra.

File.open(params[:file][:tempfile]) do |p|
   thumb = Magick::Image.read(p)
   thumb.crop_resized!(75, 75, Magick::NorthGravity)
end

The uploaded file is a jpeg, form data when uploading image includes

{:filename=>"299732_176749115737355_100002068035867_380115_618512842_n.jpg",    :type=>"image/jpeg", :name=>"file", :tempfile=>#<File:/var/folders/hf/d6vx6vg56nbd5n44jjrp84k80000gn/T/RackMultipart20120228-55947-1fd2l6c>, :head=>"Content-Disposition: form-data; name=\"file\"; filename=\"299732_176749115737355_100002068035867_380115_618512842_n.jpg\"\r\nContent-Type: image/jpeg\r\n"}

And also ImageMagick has the necessary delegates

convert -list configure

returns

DELEGATES     bzlib freetype jpeg jng jp2 lcms png tiff x11 xml zlib

So, i should be able to upload and transform a jpeg, but it whines about delegates. Also i am working on Mac OSX 10.7, maybe another weird problem with mac

like image 726
gkaykck Avatar asked Feb 28 '12 10:02

gkaykck


1 Answers

I found solution for me:

tmpfile = params[:file][:tempfile]
image = Magick::ImageList.new
bin = File.open(tmpfile, 'r'){ |file| file.read }
img = image.from_blob(bin)

I suppose problem occurs because rmagick try to define image type by file extension. But uploaded file without extension. Good luck!

like image 68
Ivan Schneider Avatar answered Oct 16 '22 10:10

Ivan Schneider