mirror of
https://github.com/docusealco/docuseal.git
synced 2026-06-23 04:10:11 +00:00
adjust autorot
This commit is contained in:
+4
-2
@@ -6,7 +6,7 @@ module ImageUtils
|
||||
|
||||
module_function
|
||||
|
||||
def load_vips(data, content_type: nil)
|
||||
def load_vips(data, content_type: nil, autorot: false)
|
||||
content_type ||= Marcel::MimeType.for(data)
|
||||
|
||||
if ICO_REGEXP.match?(content_type)
|
||||
@@ -14,7 +14,9 @@ module ImageUtils
|
||||
elsif BMP_REGEXP.match?(content_type)
|
||||
LoadBmp.call(data)
|
||||
else
|
||||
Vips::Image.new_from_buffer(data, '')
|
||||
image = Vips::Image.new_from_buffer(data, '')
|
||||
|
||||
autorot ? image.autorot : image
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
@@ -363,7 +363,7 @@ module Submissions
|
||||
|
||||
image =
|
||||
begin
|
||||
ImageUtils.load_vips(attachment.download, content_type: attachment.content_type).autorot
|
||||
ImageUtils.load_vips(attachment.download, content_type: attachment.content_type, autorot: true)
|
||||
rescue Vips::Error
|
||||
next unless attachment.content_type.starts_with?('image/')
|
||||
next if attachment.byte_size.zero?
|
||||
@@ -379,7 +379,7 @@ module Submissions
|
||||
if field['type'] == 'image' && !resized_image.has_alpha?
|
||||
StringIO.new(resized_image.colourspace(:srgb).write_to_buffer('.jpg', strip: true))
|
||||
else
|
||||
StringIO.new(resized_image.write_to_buffer('.png'))
|
||||
StringIO.new(resized_image.write_to_buffer('.png', strip: true))
|
||||
end
|
||||
|
||||
width = field['type'] == 'initials' ? 50 : 200
|
||||
|
||||
@@ -313,7 +313,7 @@ module Submissions
|
||||
attachments_data_cache[attachment.uuid] ||= attachment.download
|
||||
|
||||
ImageUtils.load_vips(attachments_data_cache[attachment.uuid],
|
||||
content_type: attachment.content_type).autorot
|
||||
content_type: attachment.content_type, autorot: true)
|
||||
rescue Vips::Error
|
||||
next unless attachment.content_type.starts_with?('image/')
|
||||
next if attachment.byte_size.zero?
|
||||
@@ -358,7 +358,8 @@ module Submissions
|
||||
image_x = area_x + ((half_width - image_width) / 2.0)
|
||||
image_y = height - area_y - image_height
|
||||
|
||||
io = StringIO.new(image.resize([scale * 4, 1].select(&:positive?).min).write_to_buffer('.png'))
|
||||
io =
|
||||
StringIO.new(image.resize([scale * 4, 1].select(&:positive?).min).write_to_buffer('.png', strip: true))
|
||||
|
||||
canvas.image(io, at: [image_x, image_y], width: image_width, height: image_height)
|
||||
|
||||
@@ -425,7 +426,8 @@ module Submissions
|
||||
|
||||
scale = [area_w / image.width, image_height / image.height].min
|
||||
|
||||
io = StringIO.new(image.resize([scale * 4, 1].select(&:positive?).min).write_to_buffer('.png'))
|
||||
io =
|
||||
StringIO.new(image.resize([scale * 4, 1].select(&:positive?).min).write_to_buffer('.png', strip: true))
|
||||
|
||||
layouter.fit([text], area_w, base_font_size / 0.65)
|
||||
.draw(canvas, area_x + TEXT_LEFT_MARGIN,
|
||||
@@ -454,7 +456,7 @@ module Submissions
|
||||
attachments_data_cache[attachment.uuid] ||= attachment.download
|
||||
|
||||
ImageUtils.load_vips(attachments_data_cache[attachment.uuid],
|
||||
content_type: attachment.content_type).autorot
|
||||
content_type: attachment.content_type, autorot: true)
|
||||
rescue Vips::Error
|
||||
next unless attachment.content_type.starts_with?('image/')
|
||||
next if attachment.byte_size.zero?
|
||||
@@ -471,7 +473,7 @@ module Submissions
|
||||
if field_type == 'image' && !resized_image.has_alpha?
|
||||
StringIO.new(resized_image.colourspace(:srgb).write_to_buffer('.jpg', strip: true))
|
||||
else
|
||||
StringIO.new(resized_image.write_to_buffer('.png'))
|
||||
StringIO.new(resized_image.write_to_buffer('.png', strip: true))
|
||||
end
|
||||
|
||||
canvas.image(
|
||||
|
||||
@@ -25,7 +25,7 @@ module Submitters
|
||||
def build_attachment(submitter, with_logo: true)
|
||||
image = generate_stamp_image(submitter, with_logo:)
|
||||
|
||||
image_data = image.write_to_buffer('.png')
|
||||
image_data = image.write_to_buffer('.png', strip: true)
|
||||
|
||||
checksum = Digest::MD5.base64digest(image_data)
|
||||
|
||||
|
||||
@@ -58,13 +58,13 @@ module Templates
|
||||
def generate_preview_image(attachment, data)
|
||||
ActiveStorage::Attachment.where(name: ATTACHMENT_NAME, record: attachment).destroy_all
|
||||
|
||||
image = ImageUtils.load_vips(data, content_type: attachment.content_type).autorot
|
||||
image = ImageUtils.load_vips(data, content_type: attachment.content_type, autorot: true)
|
||||
image = image.resize(MAX_WIDTH / image.width.to_f)
|
||||
|
||||
bitdepth = 2**image.stats.to_a[1..3].pluck(2).uniq.size
|
||||
|
||||
io = StringIO.new(image.write_to_buffer(FORMAT, compression: 6, filter: 0, bitdepth:,
|
||||
palette: true, Q: Q, dither: 0))
|
||||
palette: true, Q: Q, dither: 0, strip: true))
|
||||
|
||||
ActiveStorage::Attachment.create!(
|
||||
blob: ActiveStorage::Blob.create_and_upload!(
|
||||
|
||||
Reference in New Issue
Block a user