Visitar URL original
Extract image or pdf on windows platform bugfix by eastxing · Pull Request #90 · documentcloud/docsplit · GitHub
Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
windows platform path escape bugfix.
  • Loading branch information
eastxing committed Aug 26, 2013
commit d27377befe34b6d9fd0cd2ee4bfe16a84e54f128
5 changes: 4 additions & 1 deletion lib/docsplit.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,10 @@ module Docsplit

VERSION = '0.7.2' # Keep in sync with gemspec.

ESCAPE = lambda {|x| Shellwords.shellescape(x) }
HOST_OS = (defined?("RbConfig") ? RbConfig : Config)::CONFIG['host_os']
IS_WIN = !!HOST_OS.match(/mswin|msys|mingw|cygwin|bccwin|wince|emc/i)

ESCAPE = IS_WIN ? lambda {|x| "\"#{x}\"" } : lambda {|x| Shellwords.shellescape(x) }

ROOT = File.expand_path(File.dirname(__FILE__) + '/..')
ESCAPED_ROOT = ESCAPE[ROOT]
Expand Down
10 changes: 2 additions & 8 deletions lib/docsplit/image_extractor.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,6 @@ class ImageExtractor
DEFAULT_FORMAT = :png
DEFAULT_DENSITY = '150'

# Helper function to determine the OS
HOST_OS = (defined?("RbConfig") ? RbConfig : Config)::CONFIG['host_os']
def windows?
!!HOST_OS.match(/mswin|msys|mingw|cygwin|bccwin|wince|emc/i)
end

# Extract a list of PDFs as rasterized page images, according to the
# configuration in options.
def extract(pdfs, options)
Expand Down Expand Up @@ -45,7 +39,7 @@ def convert(pdf, size, format, previous=nil)
# Only copy image files, skip other files such as Thumbs.db under windows platform
imageFiles = File.join(directory_for(previous), '*.' + format)
FileUtils.cp(Dir.glob(imageFiles), directory)
if windows?
if IS_WIN
cmd = "set MAGICK_TMPDIR=#{tempdir} & set OMP_NUM_THREADS=2 & gm mogrify #{common} -unsharp 0x0.5+0.75 \"#{directory}/*.#{format}\" 2>&1".chomp
else
cmd = "MAGICK_TMPDIR=#{tempdir} OMP_NUM_THREADS=2 gm mogrify #{common} -unsharp 0x0.5+0.75 \"#{directory}/*.#{format}\" 2>&1".chomp
Expand All @@ -54,7 +48,7 @@ def convert(pdf, size, format, previous=nil)
raise ExtractionFailed, result if $? != 0
else
page_list(pages).each do |page|
if windows?
if IS_WIN
out_file = File.join(directory, "#{basename}_#{page}.#{format}")
cmd = "set MAGICK_TMPDIR=#{tempdir} & set OMP_NUM_THREADS=2 & gm convert +adjoin -define pdf:use-cropbox=true #{common} #{escaped_pdf}[#{page - 1}] \"#{out_file}\" 2>&1".chomp
else
Expand Down
2 changes: 1 addition & 1 deletion lib/docsplit/pdf_extractor.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ class PdfExtractor
# Provide a set of helper functions to determine the OS.
HOST_OS = (defined?("RbConfig") ? RbConfig : Config)::CONFIG['host_os']
def windows?
!!HOST_OS.match(/mswin|msys|mingw|cygwin|bccwin|wince|emc/i)
IS_WIN
end
def osx?
!!HOST_OS.match(/darwin/i)
Expand Down