adjust image load
This commit is contained in:
@@ -94,6 +94,7 @@ WORKDIR /data/docuseal
|
|||||||
ENV HOME=/home/docuseal
|
ENV HOME=/home/docuseal
|
||||||
ENV WORKDIR=/data/docuseal
|
ENV WORKDIR=/data/docuseal
|
||||||
ENV VIPS_MAX_COORD=17000
|
ENV VIPS_MAX_COORD=17000
|
||||||
|
ENV VIPS_BLOCK_UNTRUSTED=1
|
||||||
|
|
||||||
EXPOSE 3000
|
EXPOSE 3000
|
||||||
CMD ["/app/bin/bundle", "exec", "puma", "-C", "/app/config/puma.rb", "--dir", "/app"]
|
CMD ["/app/bin/bundle", "exec", "puma", "-C", "/app/config/puma.rb", "--dir", "/app"]
|
||||||
|
|||||||
@@ -16,8 +16,10 @@ module Api
|
|||||||
return render json: { error: I18n.t('form_has_been_archived') }, status: :unprocessable_content
|
return render json: { error: I18n.t('form_has_been_archived') }, status: :unprocessable_content
|
||||||
end
|
end
|
||||||
|
|
||||||
|
file = params[:file]
|
||||||
|
|
||||||
if params[:type].in?(%w[initials signature])
|
if params[:type].in?(%w[initials signature])
|
||||||
image = Vips::Image.new_from_file(params[:file].path)
|
image = ImageUtils.load_vips(file.read, content_type: file.content_type)
|
||||||
|
|
||||||
if ImageUtils.blank?(image)
|
if ImageUtils.blank?(image)
|
||||||
Rollbar.error("Empty signature: #{@submitter.id}") if defined?(Rollbar)
|
Rollbar.error("Empty signature: #{@submitter.id}") if defined?(Rollbar)
|
||||||
@@ -33,7 +35,7 @@ module Api
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
attachment = Submitters.create_attachment!(@submitter, params)
|
attachment = Submitters.create_attachment!(@submitter, file)
|
||||||
|
|
||||||
if params[:remember_signature] == 'true' && @submitter.email.present?
|
if params[:remember_signature] == 'true' && @submitter.email.present?
|
||||||
cookies.encrypted[:signature_uuids] = build_new_cookie_signatures_json(@submitter, attachment)
|
cookies.encrypted[:signature_uuids] = build_new_cookie_signatures_json(@submitter, attachment)
|
||||||
|
|||||||
@@ -1,8 +1,23 @@
|
|||||||
# frozen_string_literal: true
|
# frozen_string_literal: true
|
||||||
|
|
||||||
module ImageUtils
|
module ImageUtils
|
||||||
|
ICO_REGEXP = %r{\Aimage/(?:x-icon|vnd\.microsoft\.icon)\z}
|
||||||
|
BMP_REGEXP = %r{\Aimage/(?:bmp|x-bmp|x-ms-bmp)\z}
|
||||||
|
|
||||||
module_function
|
module_function
|
||||||
|
|
||||||
|
def load_vips(data, content_type: nil)
|
||||||
|
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
|
||||||
|
Vips::Image.new_from_buffer(data, '')
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
def blank?(image)
|
def blank?(image)
|
||||||
stats = image.stats
|
stats = image.stats
|
||||||
|
|
||||||
|
|||||||
@@ -363,7 +363,7 @@ module Submissions
|
|||||||
|
|
||||||
image =
|
image =
|
||||||
begin
|
begin
|
||||||
Submissions::GenerateResultAttachments.load_vips_image(attachment).autorot
|
ImageUtils.load_vips(attachment.download, content_type: attachment.content_type).autorot
|
||||||
rescue Vips::Error
|
rescue Vips::Error
|
||||||
next unless attachment.content_type.starts_with?('image/')
|
next unless attachment.content_type.starts_with?('image/')
|
||||||
next if attachment.byte_size.zero?
|
next if attachment.byte_size.zero?
|
||||||
|
|||||||
@@ -11,9 +11,6 @@ module Submissions
|
|||||||
'Helvetica'
|
'Helvetica'
|
||||||
end
|
end
|
||||||
|
|
||||||
ICO_REGEXP = %r{\Aimage/(?:x-icon|vnd\.microsoft\.icon)\z}
|
|
||||||
BMP_REGEXP = %r{\Aimage/(?:bmp|x-bmp|x-ms-bmp)\z}
|
|
||||||
|
|
||||||
FONT_BOLD_NAME = if File.exist?(FONT_BOLD_PATH)
|
FONT_BOLD_NAME = if File.exist?(FONT_BOLD_PATH)
|
||||||
FONT_BOLD_PATH
|
FONT_BOLD_PATH
|
||||||
else
|
else
|
||||||
@@ -313,7 +310,9 @@ module Submissions
|
|||||||
|
|
||||||
image =
|
image =
|
||||||
begin
|
begin
|
||||||
load_vips_image(attachment, attachments_data_cache).autorot
|
attachments_data_cache[attachment.uuid] ||= attachment.download
|
||||||
|
|
||||||
|
ImageUtils.load_vips(attachments_data_cache[attachment.uuid], content_type: attachment.content_type).autorot
|
||||||
rescue Vips::Error
|
rescue Vips::Error
|
||||||
next unless attachment.content_type.starts_with?('image/')
|
next unless attachment.content_type.starts_with?('image/')
|
||||||
next if attachment.byte_size.zero?
|
next if attachment.byte_size.zero?
|
||||||
@@ -451,7 +450,9 @@ module Submissions
|
|||||||
|
|
||||||
image =
|
image =
|
||||||
begin
|
begin
|
||||||
load_vips_image(attachment, attachments_data_cache).autorot
|
attachments_data_cache[attachment.uuid] ||= attachment.download
|
||||||
|
|
||||||
|
ImageUtils.load_vips(attachments_data_cache[attachment.uuid], content_type: attachment.content_type).autorot
|
||||||
rescue Vips::Error
|
rescue Vips::Error
|
||||||
next unless attachment.content_type.starts_with?('image/')
|
next unless attachment.content_type.starts_with?('image/')
|
||||||
next if attachment.byte_size.zero?
|
next if attachment.byte_size.zero?
|
||||||
@@ -1021,20 +1022,6 @@ module Submissions
|
|||||||
[]
|
[]
|
||||||
end
|
end
|
||||||
|
|
||||||
def load_vips_image(attachment, cache = {})
|
|
||||||
cache[attachment.uuid] ||= attachment.download
|
|
||||||
|
|
||||||
data = cache[attachment.uuid]
|
|
||||||
|
|
||||||
if ICO_REGEXP.match?(attachment.content_type)
|
|
||||||
LoadIco.call(data)
|
|
||||||
elsif BMP_REGEXP.match?(attachment.content_type)
|
|
||||||
LoadBmp.call(data)
|
|
||||||
else
|
|
||||||
Vips::Image.new_from_buffer(data, '')
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
def r
|
def r
|
||||||
Rails.application.routes.url_helpers
|
Rails.application.routes.url_helpers
|
||||||
end
|
end
|
||||||
|
|||||||
+11
-18
@@ -122,27 +122,20 @@ module Submitters
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def create_attachment!(submitter, params)
|
def create_attachment!(submitter, file)
|
||||||
blob =
|
raise ParamsError, 'file param is missing' if file.blank?
|
||||||
if (file = params[:file])
|
|
||||||
extension = File.extname(file.original_filename).delete_prefix('.').downcase
|
|
||||||
|
|
||||||
if DANGEROUS_EXTENSIONS.include?(extension)
|
extension = File.extname(file.original_filename).delete_prefix('.').downcase
|
||||||
raise MaliciousFileExtension, "File type '.#{extension}' is not allowed."
|
|
||||||
end
|
|
||||||
|
|
||||||
ActiveStorage::Blob.create_and_upload!(io: file.open,
|
if DANGEROUS_EXTENSIONS.include?(extension)
|
||||||
filename: file.original_filename,
|
raise MaliciousFileExtension, "File type '.#{extension}' is not allowed."
|
||||||
content_type: file.content_type)
|
end
|
||||||
else
|
|
||||||
raise ParamsError, 'file param is missing'
|
|
||||||
end
|
|
||||||
|
|
||||||
ActiveStorage::Attachment.create!(
|
blob = ActiveStorage::Blob.create_and_upload!(io: file.tap(&:rewind).open,
|
||||||
blob:,
|
filename: file.original_filename,
|
||||||
name: 'attachments',
|
content_type: file.content_type)
|
||||||
record: submitter
|
|
||||||
)
|
ActiveStorage::Attachment.create!(blob:, name: 'attachments', record: submitter)
|
||||||
end
|
end
|
||||||
|
|
||||||
def normalize_preferences(account, user, params)
|
def normalize_preferences(account, user, params)
|
||||||
|
|||||||
@@ -40,7 +40,7 @@ module Submitters
|
|||||||
def generate_stamp_image(submitter, with_logo: true)
|
def generate_stamp_image(submitter, with_logo: true)
|
||||||
logo =
|
logo =
|
||||||
if with_logo
|
if with_logo
|
||||||
Vips::Image.new_from_buffer(load_logo(submitter).read, '')
|
ImageUtils.load_vips(load_logo(submitter).read)
|
||||||
else
|
else
|
||||||
Vips::Image.new_from_buffer(TRANSPARENT_PIXEL, '').resize(WIDTH)
|
Vips::Image.new_from_buffer(TRANSPARENT_PIXEL, '').resize(WIDTH)
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -77,7 +77,7 @@ module Templates
|
|||||||
split_page: false, aspect_ratio: false, padding: nil, page_number: nil)
|
split_page: false, aspect_ratio: false, padding: nil, page_number: nil)
|
||||||
return [[], nil] if page_number && page_number != 0
|
return [[], nil] if page_number && page_number != 0
|
||||||
|
|
||||||
image = Vips::Image.new_from_buffer(io.read, '')
|
image = ImageUtils.load_vips(io.read, content_type: attachment.content_type)
|
||||||
|
|
||||||
fields = inference.call(image, confidence:, nms:, nmm:, split_page:,
|
fields = inference.call(image, confidence:, nms:, nmm:, split_page:,
|
||||||
temperature:, aspect_ratio:, padding:)
|
temperature:, aspect_ratio:, padding:)
|
||||||
|
|||||||
@@ -7,7 +7,6 @@ module Templates
|
|||||||
PREVIEW_FORMAT = '.jpg'
|
PREVIEW_FORMAT = '.jpg'
|
||||||
ATTACHMENT_NAME = 'preview_images'
|
ATTACHMENT_NAME = 'preview_images'
|
||||||
|
|
||||||
BMP_REGEXP = %r{\Aimage/(?:bmp|x-bmp|x-ms-bmp)\z}
|
|
||||||
PDF_CONTENT_TYPE = 'application/pdf'
|
PDF_CONTENT_TYPE = 'application/pdf'
|
||||||
CONCURRENCY = 2
|
CONCURRENCY = 2
|
||||||
Q = 95
|
Q = 95
|
||||||
@@ -59,14 +58,8 @@ module Templates
|
|||||||
def generate_preview_image(attachment, data)
|
def generate_preview_image(attachment, data)
|
||||||
ActiveStorage::Attachment.where(name: ATTACHMENT_NAME, record: attachment).destroy_all
|
ActiveStorage::Attachment.where(name: ATTACHMENT_NAME, record: attachment).destroy_all
|
||||||
|
|
||||||
image =
|
image = ImageUtils.load_vips(data, content_type: attachment.content_type).autorot
|
||||||
if BMP_REGEXP.match?(attachment.content_type)
|
image = image.resize(MAX_WIDTH / image.width.to_f)
|
||||||
LoadBmp.call(data)
|
|
||||||
else
|
|
||||||
Vips::Image.new_from_buffer(data, '')
|
|
||||||
end
|
|
||||||
|
|
||||||
image = image.autorot.resize(MAX_WIDTH / image.width.to_f)
|
|
||||||
|
|
||||||
bitdepth = 2**image.stats.to_a[1..3].pluck(2).uniq.size
|
bitdepth = 2**image.stats.to_a[1..3].pluck(2).uniq.size
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user