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
|
||||
|
||||
Reference in New Issue
Block a user