uploads: factor out remaining image methods to MediaFile.
This commit is contained in:
@@ -20,6 +20,17 @@ class MediaFile::Image < MediaFile
|
||||
[0, 0]
|
||||
end
|
||||
|
||||
def is_corrupt?
|
||||
image.stats
|
||||
false
|
||||
rescue Vips::Error
|
||||
true
|
||||
end
|
||||
|
||||
def is_animated?
|
||||
is_animated_gif? || is_animated_png?
|
||||
end
|
||||
|
||||
# https://github.com/jcupitt/libvips/wiki/HOWTO----Image-shrinking
|
||||
# http://jcupitt.github.io/libvips/API/current/Using-vipsthumbnail.md.html
|
||||
def preview(width, height)
|
||||
@@ -40,6 +51,14 @@ class MediaFile::Image < MediaFile
|
||||
|
||||
private
|
||||
|
||||
def is_animated_gif?
|
||||
file_ext == :gif && image.get("n-pages") > 1
|
||||
end
|
||||
|
||||
def is_animated_png?
|
||||
file_ext == :png && APNGInspector.new(file.path).inspect!.animated?
|
||||
end
|
||||
|
||||
def image
|
||||
@image ||= Vips::Image.new_from_file(file.path, fail: true)
|
||||
end
|
||||
|
||||
@@ -1,5 +1,4 @@
|
||||
class MediaFile::Ugoira < MediaFile
|
||||
extend Memoist
|
||||
class Error < StandardError; end
|
||||
attr_reader :frame_data
|
||||
|
||||
|
||||
@@ -1,10 +1,12 @@
|
||||
class MediaFile::Video < MediaFile
|
||||
extend Memoist
|
||||
|
||||
def dimensions
|
||||
[video.width, video.height]
|
||||
end
|
||||
|
||||
def duration
|
||||
video.duration
|
||||
end
|
||||
|
||||
def preview(max_width, max_height)
|
||||
preview_frame.preview(max_width, max_height)
|
||||
end
|
||||
@@ -13,6 +15,10 @@ class MediaFile::Video < MediaFile
|
||||
preview_frame.crop(max_width, max_height)
|
||||
end
|
||||
|
||||
def has_audio?
|
||||
video.audio_channels.present?
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def video
|
||||
|
||||
Reference in New Issue
Block a user