我正在使用 Carrierwave gem 上传从 iPhone 录制的视频,并创建使用 carrierwave-video-thumbnailer gem 上传的视频的缩略图.
现在我面临着由 carrierwave-video-thumbnailer gem 生成的旋转缩略图的问题。我需要根据视频方向旋转到纵向。
请在下面查看我的 VideoUploader 类。
class VideoUploader < CarrierWave::Uploader::Base
include CarrierWave::Video
include CarrierWave::Video::Thumbnailer
# Include RMagick or MiniMagick support:
# include CarrierWave::RMagick
# include CarrierWave::MiniMagick
storage :file
def store_dir
"uploads/#{model.class.to_s.underscore}/#{mounted_as}/#{model.id}"
end
version :thumb do
process thumbnail: [{format: 'jpg', quality: 7, size: 640, strip: false, logger: Rails.logger}]
def full_filename for_file
png_name for_file, version_name
end
process :set_content_type_jpg
end
def png_name for_file, version_name
%Q{#{version_name}_#{for_file.chomp(File.extname(for_file))}.jpg}
end
def set_content_type_jpg(*args)
Rails.logger.debug "#{file.content_type}"
self.file.instance_variable_set(:@content_type, "image/jpeg")
end
end
你应该包括:
include CarrierWave::RMagick
并基于this
process :do_stuff
def do_stuff(blur_factor)
manipulate! do |img|
img = img.auto_orient
# or something similar
end
end
可以找到 RMagick 的完整操作列表 here .
我是一名优秀的程序员,十分优秀!