media file: fix overly large thumbnails for animated GIFs.
Fix regression in ef2857667 that caused animated GIFs and PNGs to
generate thumbnails that were larger than 150x150.
Also fix a bug with cropped previews not being generated for animated
GIFs and PNGs.
This commit is contained in:
@@ -38,26 +38,28 @@ class MediaFile::Image < MediaFile
|
||||
# @see https://github.com/jcupitt/libvips/wiki/HOWTO----Image-shrinking
|
||||
# @see http://jcupitt.github.io/libvips/API/current/Using-vipsthumbnail.md.html
|
||||
def preview(width, height)
|
||||
if is_animated?
|
||||
FFmpeg.new(file).smart_video_preview
|
||||
else
|
||||
output_file = Tempfile.new(["image-preview", ".jpg"])
|
||||
resized_image = image.thumbnail_image(width, height: height, **THUMBNAIL_OPTIONS)
|
||||
resized_image.jpegsave(output_file.path, **JPEG_OPTIONS)
|
||||
|
||||
MediaFile::Image.new(output_file)
|
||||
end
|
||||
end
|
||||
|
||||
def crop(width, height)
|
||||
output_file = Tempfile.new(["image-crop", ".jpg"])
|
||||
resized_image = image.thumbnail_image(width, height: height, **CROP_OPTIONS)
|
||||
output_file = Tempfile.new(["image-preview", ".jpg"])
|
||||
resized_image = preview_frame.image.thumbnail_image(width, height: height, **THUMBNAIL_OPTIONS)
|
||||
resized_image.jpegsave(output_file.path, **JPEG_OPTIONS)
|
||||
|
||||
MediaFile::Image.new(output_file)
|
||||
end
|
||||
|
||||
private
|
||||
def crop(width, height)
|
||||
output_file = Tempfile.new(["image-crop", ".jpg"])
|
||||
resized_image = preview_frame.image.thumbnail_image(width, height: height, **CROP_OPTIONS)
|
||||
resized_image.jpegsave(output_file.path, **JPEG_OPTIONS)
|
||||
|
||||
MediaFile::Image.new(output_file)
|
||||
end
|
||||
|
||||
def preview_frame
|
||||
if is_animated?
|
||||
FFmpeg.new(file).smart_video_preview
|
||||
else
|
||||
self
|
||||
end
|
||||
end
|
||||
|
||||
def is_animated_gif?
|
||||
file_ext == :gif && image.get("n-pages") > 1
|
||||
|
||||
Reference in New Issue
Block a user