Giter Club home page Giter Club logo

multishot's Introduction

multishot

A lib for generating multiple screenshots

Getting Started

Dependencies

Currently only works on osx.

brew install webkit2png

Install

npm install multishot --save-dev
npm install multishot -g

The CLI

Overview

Usage: multishot [opts]

Options:
  -o     Output directory                                        [default: process.cwd()]
  -t     Temp directory. Note: This directory will be truncated. [default: "/tmp/multishot/"]
  -u     List of urls to use.
  -f     File containing list of urls (One url per line).
  -p     Prefix for output file.
  -d     Device Profile. Pass with no option to see available presets.
  -w     Sets viewport width.
  -h     Sets viewport height.
  -a     Sets user agent.
  --tpl  Template file.

Usage Examples

multishot -f example/urls.txt -o ~/Desktop
multishot -u http://google.com -o ~/Desktop

Text file input

The text file must contain one url per line. Blank lines are permitted for formatting. You may optionally group urls by putting a group name on its own line. Note: group names cannot contain http.

See example/urls.txt for an example

The API

Usage

var Screenshot = require('multishot').Screenshot;

var urls = [
    {
      group: 'Circles',
      url: 'http://leanin.org/circles/'
    },
    {
      group: 'Circles',
      url: 'http://leanin.org/circle-login/'
    },
    {
      group: 'Circles',
      url: 'http://leanin.org/circle-faqs/'
    },
    'http://leanin.org',
    {
      url: 'http://leanin.org/team/'
    },
    {
      group: 'News+Inspiration',
      url: 'http://leanin.org/news-inspiration/'
    },
  ];

var options = {
  temp: '/tmp/multishot/',
  output: '/tmp/multishot/',
  style: {
    bodyBackground: 'pink',
    custom: '.url { text-decoration: underline; }'
  }
};

var shot = new Screenshot(urls, options);

shot.on('start', function(){
  console.log('starting');
});

shot.on('progress', function() {
  // Update progress bar if you have one
});

shot.on('complete', function(file) {
  // do something on complete
});

shot.on('err', function(err) {
  // Something bad happened
});

shot.start();

Events

start Triggered when start() is called and passes the webkit2png check.

progress
Triggered every time an image is rendered and once on complete.

complete
Triggered once the file image has been generated. Returns the path to composed image.

err
Returns an exception or string.

Options

output
A path to render the final composed image. Will be created if it doesn't exist.

temp
Temp path where screenshots will be taken. Will be created and truncated each run so be careful when setting. Default: /tmp/multishot/

template
A handlebars HTML file to use as the combined template. See custom template section for more information.

prefix Prefix will be added to the output file. Example: dev-20131015.png

Custom Templates

Multishot uses a handlebars template to generate the combined image. While the default template is nice, you may want to customize it:

Example:

var shot = new Screenshot(urls, {
  template: '/Users/WalterWhite/templates/multishot.html'
});

The bare minimum your template should have is:

<!DOCTYPE html>
<html>
<head>
  <base href="{{base}}">
</head> 
<body>
  {{#each grouped}}
  <div class="group">
    <h2>{{@key}}</h2>
    {{#each this}}
    <div class="screenshot-container">
      <div class="url">{{this.url}}</div>
      <img src="{{this.group}}/{{this.index}}-full.png" class="screenshot">
    </div>
    {{/each}}
   </div>
  {{/each}}
</body>
</html>

Templates are passed the following variables:

base
Base path to load images

grouped
Object containing all grouped images. See example HTML above for usage.

styles
Various different values that a template can use to customize the css. See Styles section for available values.

Custom Styles

These are the default styles:

Variable Value
background #fff
bodyFontFamily "Lato", sans-serif
bodyFontWeight 400
bodyFontColor #7f8c8d
bodyFontSize 12px
bodyLineHeight 17px
groupMargin 40px 0
screenshotImgBorder 4px solid #d35400
h2FontSize 24px
h2FontColor #2C3E50
h2FontWeight 700
h2Margin 2px 0
urlFontStyle italic

You can override or add new variables by passing them as properties to the styles option value.

If you want to pass in a full block of css:

var options = {
  styles: {
    custom: '.someSelector{ background: white }'
  }
};

The custom property can contain any css as long as its valid. If you need any more control you should look into writing a unique template to match your needs.

multishot's People

Contributors

dawnerd avatar jgallen23 avatar

Stargazers

 avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar

Forkers

imclab

multishot's Issues

Diff tool

Do you think this should be in the same app or separate? If it's in the same, multishot needs to be a lot smarter to figure out the last screenshot taken. If we do a separate tool, it could be more manual where it's just imagediff image1.jpg image2.jpg. Down side to more manual is it's tougher to automate.

Thoughts?

Grouping

good idea from @apermanentwreck: add the ability to group urls. Each group should be on a new line in the image.

for the text file, maybe an extra line break means a group

wrap option

If set, wrap the images on the next line. So if I pass wrap: 4, after 4 images, put the 5 below the first

npm install webkit2png?

similar to how node-phantomjs downloads the binary for phantomjs, would be interesting to see if we could get webkit2png to download via npm as well. Low priority, but could make it so people would be more likely to use the tool

cli tool

use something like optimist to take in urls (comma separated)

Parallelize

fire up multiple instances of webkit2png to speed up the process

pass in option for name/prefix

I would be nice to be able to pass in an optional name param that will prefix the name of the file. Use case is taking screenshots for dev, stage and prod. We could also call it prefix if you prefer that.

cookie support

--cookies name=value,name=value

probably would be easiest to just have the value for --cookies be the same as webkit2png

Error

[[email protected]] ~/code/multishot [master]: ./bin/multishot -u http://leanin.org -p dev
Capturing screenshots. This might take a while.

/Users/jga/code/multishot/lib/screenshot.js:123
      this.urls = (typeof url === 'string') ? [url] : url;
                                                      ^
ReferenceError: url is not defined
    at EventEmitter.<anonymous> (/Users/jga/code/multishot/lib/screenshot.js:123:55)
    at /Users/jga/code/multishot/node_modules/async/lib/async.js:229:13
    at /Users/jga/code/multishot/node_modules/async/lib/async.js:116:25
    at /Users/jga/code/multishot/node_modules/async/lib/async.js:24:16
    at /Users/jga/code/multishot/node_modules/async/lib/async.js:226:17
    at /Users/jga/code/multishot/node_modules/async/lib/async.js:513:34
    at /Users/jga/code/multishot/lib/screenshot.js:117:13
    at /Users/jga/code/multishot/node_modules/async/lib/async.js:116:25
    at /Users/jga/code/multishot/node_modules/async/lib/async.js:24:16
    at Object.oncomplete (fs.js:107:15)

Not working

multishot -u http://staging.leanin.org -o .

Here's what I get back:
2013103-full

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.