The problem occurs when i try to manipulate an image uploaded from sinatra.
当我尝试操纵从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
上传的文件是jpeg,上传图片时的表格数据包括
{: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
而ImageMagick也有必要的代表
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
所以,我应该能够上传和转换jpeg,但它会对代表抱怨。我也在Mac OSX 10.7上工作,也许是mac的另一个奇怪的问题
1 个解决方案
#1
9
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!
我想问题是因为rmagick试图通过文件扩展名定义图像类型。但上传的文件没有扩展名。祝你好运!
#1
9
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!
我想问题是因为rmagick试图通过文件扩展名定义图像类型。但上传的文件没有扩展名。祝你好运!