saving multiple formats: png, pdf, jpg

14 views
Skip to first unread message

Stephen Bannasch

unread,
Aug 20, 2013, 11:21:20 AM8/20/13
to shutter...@googlegroups.com
I've got a branch (not ready to pull) named wip-pdf which adds pdf generation.

https://github.com/stepheneb/shutterbug/tree/wip-pdf

I'm wondering how best to support generation of multiple formats.

Currently wip-pdf calls phantomjs twice, once to generate the png and again to generate the pdf file:

https://github.com/stepheneb/shutterbug/blob/d391f2d91fd72b76299ef33aab813b160ca2732c/lib/shutterbug/phantom_job.rb#L70-L82

This is obviously inefficient. I'll bet that making an instance of phantomjs and laying out the page takes a huge portion of time compared to the call that renders the page into a file in resterize.js.

So it would be better to make one instance, lay out the page and then execute: page.render(output); sequentially for all desired output formats.

https://github.com/stepheneb/shutterbug/blob/d391f2d91fd72b76299ef33aab813b160ca2732c/lib/shutterbug/rasterize.js#L26

The format used is determined by the output file suffix:

png: *.png
pdf: *.pdf
jpg: *.jpg

I haven't tested the jpg version yet but it looks like phantonjs supports that also.

A simple implementation would just save all three formats and add the routes/implementation for jpg the same as png and pdf.

If for example png and pdf were never used we'd save space by only saving jpgs.

We could use some kind of configuration system for specifying the default operation.

Noah Paessel

unread,
Aug 21, 2013, 11:15:53 AM8/21/13
to shutter...@googlegroups.com
On Tue, Aug 20, 2013 at 11:21 AM, Stephen Bannasch <stephen....@deanbrook.org> wrote:
I've got a branch (not ready to pull) named wip-pdf which adds pdf generation.   https://github.com/stepheneb/shutterbug/tree/wip-pdf

I'm wondering how best to support generation of multiple formats.
... 
 
it would be better to make one instance, lay out the page and then execute: page.render(output); sequentially for all desired output formats.
 ... 

A simple implementation would just save all three formats and add the routes/implementation for jpg the same as png and pdf.
 

This seems like a good way to start.  We would have to modify the phantom script rasterize.js to take multiple output file arguments on the command line. 

We could use some kind of configuration system for specifying the default operation.


This would be a good place to specify the list of file formats to be exported.
 
While reviewing this code ( https://github.com/concord-consortium/shutterbug/blob/master/lib/shutterbug/configuration.rb#L39-L51 ), one pattern jumped out at me.  Each filetype specifies a 1.) a file-system path, 2.) a regular expression, and 3.) a subclass of BugFile.  A future improvement could be to extract all of those concerns into one class for each filetype we want to provide exports for, to keep configuration.rb small and understandable.  Configuration.rb would just keep a list of export file class, and proxy all the *_path and *_regex methods through the configured export plugins.  

But this can happen later ;)

- n


Reply all
Reply to author
Forward
0 new messages