MediaFile: allow generating thumbnails for corrupt files.
We need this so we can regenerate thumbnails for old posts with corrupted images.
This commit is contained in:
@@ -8,7 +8,7 @@ class MediaFile
|
|||||||
extend Memoist
|
extend Memoist
|
||||||
include ActiveModel::Serializers::JSON
|
include ActiveModel::Serializers::JSON
|
||||||
|
|
||||||
attr_accessor :file
|
attr_accessor :file, :strict
|
||||||
|
|
||||||
# delegate all File methods to `file`.
|
# delegate all File methods to `file`.
|
||||||
delegate *(File.instance_methods - MediaFile.instance_methods), to: :file
|
delegate *(File.instance_methods - MediaFile.instance_methods), to: :file
|
||||||
@@ -71,9 +71,13 @@ class MediaFile
|
|||||||
end
|
end
|
||||||
|
|
||||||
# Initialize a MediaFile from a regular File.
|
# Initialize a MediaFile from a regular File.
|
||||||
# @param file [File] the image file
|
#
|
||||||
def initialize(file, **options)
|
# @param file [File] The image file.
|
||||||
|
# @param strict [Boolean] If true, raise errors if the file is corrupt. If false,
|
||||||
|
# try to process corrupt files without raising any errors.
|
||||||
|
def initialize(file, strict: true, **options)
|
||||||
@file = file
|
@file = file
|
||||||
|
@strict = strict
|
||||||
end
|
end
|
||||||
|
|
||||||
# @return [Array<(Integer, Integer)>] the width and height of the file
|
# @return [Array<(Integer, Integer)>] the width and height of the file
|
||||||
|
|||||||
@@ -120,7 +120,7 @@ class MediaFile::Image < MediaFile
|
|||||||
|
|
||||||
# @return [Vips::Image] the Vips image object for the file
|
# @return [Vips::Image] the Vips image object for the file
|
||||||
def image
|
def image
|
||||||
Vips::Image.new_from_file(file.path, fail: true).autorot
|
Vips::Image.new_from_file(file.path, fail: strict).autorot
|
||||||
end
|
end
|
||||||
|
|
||||||
def video
|
def video
|
||||||
|
|||||||
Reference in New Issue
Block a user