lib/grim/page.rb in grim-0.2.1 vs lib/grim/page.rb in grim-0.2.2
- old
+ new
@@ -17,22 +17,31 @@
# Extracts the selected page and turns it into an image.
# Tested on png and jpeg.
#
# path - String of the path to save to
+ # options - Hash of options to customize the saving of the image
+ # (ie: width, density, and quality)
#
# For example:
#
# pdf[1].save(/path/to/save/image.png)
# # => true
#
# Returns a File.
#
- def save(path)
- SafeShell.execute("convert", "-resize", Grim::WIDTH, "-antialias", "-render",
- "-quality", Grim::QUALITY, "-colorspace", "RGB",
- "-interlace", "none", "-density", Grim::DENSITY,
+ def save(path, options={})
+ raise PathMissing if path.nil? || path !~ /\S/
+
+ width = options.fetch(:width, Grim::WIDTH)
+ density = options.fetch(:density, Grim::DENSITY)
+ quality = options.fetch(:quality, Grim::QUALITY)
+
+ SafeShell.execute("convert", "-resize", width, "-antialias", "-render",
+ "-quality", quality, "-colorspace", "RGB",
+ "-interlace", "none", "-density", density,
"#{@pdf.path}[#{@index}]", path)
+
File.exists?(path)
end
# Extracts the text from the selected page.
#
\ No newline at end of file