我正在尝试使用carrierwave(雾)为我的图像上传器创建新版本,我试图做一个条件版本来检查是否gif摆脱动画并转换为jpg但由于某种原因它没有虽然调试在这方面有点难度,但是不行。
这是我的代码
class SourceImageUploader < CarrierWave::Uploader::Base
# Include RMagick or MiniMagick support:
include CarrierWave::MiniMagick
include CarrierWave::MimeTypes
include CarrierWave::MimetypeFu
# Choose what kind of storage to use for this uploader:
storage :fog
process :set_content_type
# Override the directory where uploaded files will be stored.
# This is a sensible default for uploaders that are meant to be mounted:
def store_dir
"uploads/#{model.class.to_s.underscore}/#{mounted_as}/#{model.id}"
end
version :big_thumb do
process :resize_to_fit => [600, 99999]
end
version :small_thumb do
process :resize_to_fit => [200, 99999]
end
version :first_frame do
process :remove_animation
end
def filename
"#{secure_token}.#{file.extension}" if original_filename.present?
end
protected
def secure_token
var = :"@#{mounted_as}_secure_token"
model.instance_variable_get(var) or model.instance_variable_set(var, SecureRandom.hex(2))
end
# def is_gif?(new_file)
# new_file.content_type.include? 'gif' rescue false
# end
def remove_animation
if content_type == 'image/gif'
manipulate! { |image| image.collapse! }
end
end
我试图用户is_gif?方法作为条件版本条件,但它不起作用。
有什么建议吗?
干杯!