adjust load vips

This commit is contained in:
Pete Matsyburka committed 2026-09-20 13:30:27 +03:00
1 parent de1af49348
commit 5432978c0d
1 file changed
+18 -8
+18 -8
View File
@@ -1,23 +1,33 @@
# frozen_string_literal: true
module ImageUtils
PNG_REGEXP = %r{\Aimage/(?:png|apng|vnd\.mozilla\.apng)\z}
JPEG_REGEXP = %r{\Aimage/(?:jpeg|jpg|pjpeg)\z}
ICO_REGEXP = %r{\Aimage/(?:x-icon|vnd\.microsoft\.icon)\z}
BMP_REGEXP = %r{\Aimage/(?:bmp|x-bmp|x-ms-bmp)\z}
UnsupportedFormat = Class.new(StandardError)
module_function
def load_vips(data, content_type: nil, autorot: false)
content_type ||= Marcel::MimeType.for(data)
if ICO_REGEXP.match?(content_type)
LoadIco.call(data)
elsif BMP_REGEXP.match?(content_type)
LoadBmp.call(data)
else
image = Vips::Image.new_from_buffer(data, '')
image =
case content_type
when PNG_REGEXP
Vips::Image.pngload_buffer(data)
when JPEG_REGEXP
Vips::Image.jpegload_buffer(data)
when ICO_REGEXP
LoadIco.call(data)
when BMP_REGEXP
LoadBmp.call(data)
else
raise UnsupportedFormat, content_type.to_s
end
autorot ? image.autorot : image
end
autorot ? image.autorot : image
end
def blank?(image)