fix pdf generation images

pull/105/head
Alex Turchyn 2 years ago
parent ead316df00
commit 5352a25ede

@ -46,11 +46,14 @@ module Submissions
when 'image', 'signature' when 'image', 'signature'
attachment = submitter.attachments.find { |a| a.uuid == value } attachment = submitter.attachments.find { |a| a.uuid == value }
io = StringIO.new(download_supported_image_data(attachment))
scale = [(area['w'] * width) / attachment.metadata['width'], scale = [(area['w'] * width) / attachment.metadata['width'],
(area['h'] * height) / attachment.metadata['height']].min (area['h'] * height) / attachment.metadata['height']].min
image = Vips::Image.new_from_buffer(attachment.download, '')
image = image.autorot.resize([scale * 4, 1].min)
io = StringIO.new(image.write_to_buffer('.png'))
canvas.image( canvas.image(
io, io,
at: [ at: [
@ -244,7 +247,7 @@ module Submissions
page.box.height = attachment.metadata['height'] * scale page.box.height = attachment.metadata['height'] * scale
page.canvas.image( page.canvas.image(
StringIO.new(download_supported_image_data(attachment)), StringIO.new(attachment.preview_images.first.download),
at: [0, 0], at: [0, 0],
width: page.box.width, width: page.box.width,
height: page.box.height height: page.box.height
@ -253,15 +256,6 @@ module Submissions
pdf pdf
end end
def download_supported_image_data(attachment)
if SUPPORTED_IMAGE_TYPES.include?(attachment.content_type)
attachment.download
else
Vips::Image.new_from_buffer(attachment.download, '')
.write_to_buffer('.png')
end
end
def h def h
Rails.application.routes.url_helpers Rails.application.routes.url_helpers
end end

@ -28,7 +28,7 @@ module Templates
ActiveStorage::Attachment.where(name: ATTACHMENT_NAME, record: attachment).destroy_all ActiveStorage::Attachment.where(name: ATTACHMENT_NAME, record: attachment).destroy_all
image = Vips::Image.new_from_buffer(binary, '') image = Vips::Image.new_from_buffer(binary, '')
image = image.resize(MAX_WIDTH / image.width.to_f) image = image.autorot.resize(MAX_WIDTH / image.width.to_f)
io = StringIO.new(image.write_to_buffer(FORMAT, Q: Q, interlace: true)) io = StringIO.new(image.write_to_buffer(FORMAT, Q: Q, interlace: true))

Loading…
Cancel
Save