我使用载波上传 gif,效果很好,当我尝试生成拇指版本并将 gif 转换为 jpeg(仅将 gif 中的第一个图像作为拇指)时,问题出现了,我收到错误:
LocalJumpError in ImagesController#create
no block given (yield)
app/controllers/images_controller.rb:21:in `new'
app/controllers/images_controller.rb:21:in `create'
Request
参数:
{"utf8"=>"✓",
"authenticity_token"=>"lPEjP1WtPxFdizL2/FAWGHzOZPtecb5nKzKO8dg5ZdE=",
"image"=>{"image"=>#<ActionDispatch::Http::UploadedFile:0x007ff5d4cdc720 @original_filename="some-file-name.gif",
@content_type="image/gif",
@headers="Content-Disposition: form-data; name=\"image[image]\"; filename=\"some-file-name.gif\"\r\nContent-Type: image/gif\r\n",
@tempfile=#<File:/var/folders/c8/1t7w8nln4b3bvs4_nv2cyn2m0000gt/T/RackMultipart20120326-5101-gcyvk0>>,
"remote_image_url"=>"",
"title"=>"The red panda",
"nsw"=>"0"},
"commit"=>"Roll GIF"}
这是我用来生成拇指的代码:
version :thumb do
process :resize_to_limit => [200, 200]
process :convert => 'jpg'
end
希望大家能够帮忙并提前致谢。
要使用 Carrierwave 从 gif 图像中删除动画,您可以定义以下处理器:
def remove_animation
manipulate! do |img, index|
index == 0 ? img : nil
end
end
因此,拇指版本的代码将是:
version :thumb do
process :remove_animation
process :resize_to_limit => [200, 200]
process :convert => 'jpg'
end
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)