use progressive jpeg for previews

pull/105/head
Alex Turchyn 2 years ago
parent e227fe480e
commit 897f4a2291

@ -16,7 +16,7 @@
ref="input"
type="file"
class="hidden"
accept=".pdf"
accept="image/*, application/pdf"
multiple
@change="upload"
>

@ -12,6 +12,8 @@ Rails.configuration.to_prepare do
end
LoadActiveStorageConfigs.call
rescue StandardError
rescue StandardError => e
Rails.logger.debug(e)
nil
end

@ -30,7 +30,7 @@ module Templates
image = Vips::Image.new_from_buffer(binary, '')
image = image.resize(MAX_WIDTH / image.width.to_f)
io = StringIO.new(image.write_to_buffer(FORMAT, Q: Q))
io = StringIO.new(image.write_to_buffer(FORMAT, Q: Q, interlace: true))
ActiveStorage::Attachment.create!(
blob: ActiveStorage::Blob.create_and_upload!(
@ -46,12 +46,13 @@ module Templates
binary = attachment.download
ActiveStorage::Attachment.where(name: ATTACHMENT_NAME, record: attachment).destroy_all
number_of_pages = HexaPDF::Document.new(io: StringIO.new(binary)).pages.size - 1
(0..).each do |page_number|
(0..number_of_pages).each do |page_number|
page = Vips::Image.new_from_buffer(binary, '', dpi: DPI, page: page_number)
page = page.resize(MAX_WIDTH / page.width.to_f)
io = StringIO.new(page.write_to_buffer(FORMAT, Q: Q))
io = StringIO.new(page.write_to_buffer(FORMAT, Q: Q, interlace: true))
ActiveStorage::Attachment.create!(
blob: ActiveStorage::Blob.create_and_upload!(
@ -61,8 +62,6 @@ module Templates
name: ATTACHMENT_NAME,
record: attachment
)
rescue Vips::Error
break
end
end
end

Loading…
Cancel
Save