uploads: factor out remaining image methods to MediaFile.

This commit is contained in:
evazion
2020-05-19 02:18:30 -05:00
parent 45064853de
commit 364343453c
7 changed files with 56 additions and 88 deletions

View File

@@ -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