use progressive jpeg for previews
This commit is contained in:
@@ -16,7 +16,7 @@
|
|||||||
ref="input"
|
ref="input"
|
||||||
type="file"
|
type="file"
|
||||||
class="hidden"
|
class="hidden"
|
||||||
accept=".pdf"
|
accept="image/*, application/pdf"
|
||||||
multiple
|
multiple
|
||||||
@change="upload"
|
@change="upload"
|
||||||
>
|
>
|
||||||
|
|||||||
@@ -12,6 +12,8 @@ Rails.configuration.to_prepare do
|
|||||||
end
|
end
|
||||||
|
|
||||||
LoadActiveStorageConfigs.call
|
LoadActiveStorageConfigs.call
|
||||||
rescue StandardError
|
rescue StandardError => e
|
||||||
|
Rails.logger.debug(e)
|
||||||
|
|
||||||
nil
|
nil
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -30,7 +30,7 @@ module Templates
|
|||||||
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.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!(
|
ActiveStorage::Attachment.create!(
|
||||||
blob: ActiveStorage::Blob.create_and_upload!(
|
blob: ActiveStorage::Blob.create_and_upload!(
|
||||||
@@ -46,12 +46,13 @@ module Templates
|
|||||||
binary = attachment.download
|
binary = attachment.download
|
||||||
|
|
||||||
ActiveStorage::Attachment.where(name: ATTACHMENT_NAME, record: attachment).destroy_all
|
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 = Vips::Image.new_from_buffer(binary, '', dpi: DPI, page: page_number)
|
||||||
page = page.resize(MAX_WIDTH / page.width.to_f)
|
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!(
|
ActiveStorage::Attachment.create!(
|
||||||
blob: ActiveStorage::Blob.create_and_upload!(
|
blob: ActiveStorage::Blob.create_and_upload!(
|
||||||
@@ -61,8 +62,6 @@ module Templates
|
|||||||
name: ATTACHMENT_NAME,
|
name: ATTACHMENT_NAME,
|
||||||
record: attachment
|
record: attachment
|
||||||
)
|
)
|
||||||
rescue Vips::Error
|
|
||||||
break
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
Reference in New Issue
Block a user