mirror of
https://github.com/scinote-eln/scinote-web.git
synced 2025-10-06 11:57:16 +08:00
Move PDF thumbnail generation to ImageMagick
Closes SCI-3579
This commit is contained in:
parent
290e452aec
commit
33cc3c29d1
1 changed files with 19 additions and 9 deletions
|
@ -10,16 +10,26 @@ module Paperclip
|
||||||
dst = TempfileFactory.new.generate("#{basename}.#{options[:format]}")
|
dst = TempfileFactory.new.generate("#{basename}.#{options[:format]}")
|
||||||
|
|
||||||
begin
|
begin
|
||||||
Paperclip.run(
|
if @file.content_type == 'application/pdf'
|
||||||
libreoffice_path,
|
# We use special convert options for PDFs to improve quality and
|
||||||
"--headless --invisible --convert-to png --outdir #{directory} #{@file.path}"
|
# background, we append [0] to convert only the first page
|
||||||
)
|
convert(
|
||||||
|
":source -resize '#{options[:geometry]}' -format #{options[:format]} -flatten -quality 70 :dest",
|
||||||
|
source: File.expand_path(@file.path) + '[0]',
|
||||||
|
dest: File.expand_path(dst.path)
|
||||||
|
)
|
||||||
|
else
|
||||||
|
Paperclip.run(
|
||||||
|
libreoffice_path,
|
||||||
|
"--headless --invisible --convert-to png --outdir #{directory} #{@file.path}"
|
||||||
|
)
|
||||||
|
|
||||||
convert(
|
convert(
|
||||||
":source -resize '#{options[:geometry]}' -format #{options[:format]} #{options[:convert_options]} :dest",
|
":source -resize '#{options[:geometry]}' -format #{options[:format]} #{options[:convert_options]} :dest",
|
||||||
source: File.expand_path(original_preview_file),
|
source: File.expand_path(original_preview_file),
|
||||||
dest: File.expand_path(dst.path)
|
dest: File.expand_path(dst.path)
|
||||||
)
|
)
|
||||||
|
end
|
||||||
ensure
|
ensure
|
||||||
File.delete(original_preview_file) if File.file?(original_preview_file)
|
File.delete(original_preview_file) if File.file?(original_preview_file)
|
||||||
end
|
end
|
||||||
|
|
Loading…
Add table
Reference in a new issue