diff --git a/app/logical/media_file.rb b/app/logical/media_file.rb index 6b3ea53e5..8ca597acf 100644 --- a/app/logical/media_file.rb +++ b/app/logical/media_file.rb @@ -8,7 +8,7 @@ class MediaFile extend Memoist include ActiveModel::Serializers::JSON - attr_accessor :file + attr_accessor :file, :strict # delegate all File methods to `file`. delegate *(File.instance_methods - MediaFile.instance_methods), to: :file @@ -71,9 +71,13 @@ class MediaFile end # 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 + @strict = strict end # @return [Array<(Integer, Integer)>] the width and height of the file diff --git a/app/logical/media_file/image.rb b/app/logical/media_file/image.rb index 9d1cc7c0f..5f7cddf47 100644 --- a/app/logical/media_file/image.rb +++ b/app/logical/media_file/image.rb @@ -120,7 +120,7 @@ class MediaFile::Image < MediaFile # @return [Vips::Image] the Vips image object for the file def image - Vips::Image.new_from_file(file.path, fail: true).autorot + Vips::Image.new_from_file(file.path, fail: strict).autorot end def video