Permalink
Browse files

Issue #16, customizable graphicsmagick --density when extracting images.

  • Loading branch information...
jashkenas committed Sep 13, 2011
1 parent 6552b45 commit 54010954333d70eb7015d4e958fd9f572f4df09f
Showing with 10 additions and 4 deletions.
  1. +4 −2 index.html
  2. +3 −0 lib/docsplit/command_line.rb
  3. +3 −2 lib/docsplit/image_extractor.rb
View
@@ -177,13 +177,15 @@ <h2 id="usage">Usage</h2>
</p>
<p>
- <b class="header">images</b><code>--size --format --pages </code>
+ <b class="header">images</b><code>--size --format --pages --density</code>
<span class="alias">Ruby: <b>extract_images</b></span>
<br />
Generates an image for each page in the document at the specified resolution
and format. Pass <tt>--pages</tt> or <tt>-p</tt> to choose the specific pages to
image. Passing<br /> <tt>--size</tt> or <tt>-s</tt> will specify the desired
- image resolution, and <tt>--format</tt> or <tt>-f</tt> will select the format of the final images.
+ image resolution, <tt>--density</tt> or <tt>-d</tt> will specify the DPI to rasterize the images
+ at during conversion by GraphicsMagick, and <tt>--format</tt> or <tt>-f</tt>
+ will select the format of the final images.
</p>
<pre>
docsplit images example.pdf
@@ -85,6 +85,9 @@ def parse_options
opts.on('-f', '--format [FORMAT]', 'set image format (pdf, jpg, gif...)') do |t|
@options[:format] = t.split(',')
end
+ opts.on('-d', '--density [NUM]', 'set image density (DPI) when rasterizing') do |d|
+ @options[:density] = d
+ end
opts.on('--[no-]ocr', 'force OCR to be used, or disable OCR') do |o|
@options[:ocr] = o
end
@@ -4,9 +4,9 @@ module Docsplit
# nicely sized images.
class ImageExtractor
- DENSITY_ARG = "-density 150"
MEMORY_ARGS = "-limit memory 256MiB -limit map 512MiB"
DEFAULT_FORMAT = :png
+ DEFAULT_DENSITY = '150'
# Extract a list of PDFs as rasterized page images, according to the
# configuration in options.
@@ -34,7 +34,7 @@ def convert(pdf, size, format, previous=nil)
pages = @pages || '1-' + Docsplit.extract_length(pdf).to_s
escaped_pdf = ESCAPE[pdf]
FileUtils.mkdir_p(directory) unless File.exists?(directory)
- common = "#{MEMORY_ARGS} #{DENSITY_ARG} #{resize_arg(size)} #{quality_arg(format)}"
+ common = "#{MEMORY_ARGS} -density #{@density} #{resize_arg(size)} #{quality_arg(format)}"
if previous
FileUtils.cp(Dir[directory_for(previous) + '/*'], directory)
result = `MAGICK_TMPDIR=#{tempdir} OMP_NUM_THREADS=2 gm mogrify #{common} -unsharp 0x0.5+0.75 \"#{directory}/*.#{format}\" 2>&1`.chomp
@@ -58,6 +58,7 @@ def convert(pdf, size, format, previous=nil)
def extract_options(options)
@output = options[:output] || '.'
@pages = options[:pages]
+ @density = options[:density] || DEFAULT_DENSITY
@formats = [options[:format] || DEFAULT_FORMAT].flatten
@sizes = [options[:size]].flatten.compact
@sizes = [nil] if @sizes.empty?

0 comments on commit 5401095

Please sign in to comment.