Git Product home page Git Product logo

grunt-photobox's Introduction

grunt-photobox

Build Status NPM version Dependency Status Code Climate Built with Grunt

image

Plugin to prevent your project of broken layout via screenshot photo sessions of your site.

Getting Started

This plugin requires Grunt ~0.4.1

If you haven't used Grunt before, be sure to check out the Getting Started guide, as it explains how to create a Gruntfile as well as install and use Grunt plugins. Once you're familiar with that process, you may install this plugin with this command:

npm install grunt-photobox --save-dev

Once the plugin has been installed, it may be enabled inside your Gruntfile with this line of JavaScript:

grunt.loadNpmTasks('grunt-photobox');

The "photobox" task

Overview

In your project's Gruntfile, add a section named photobox to the data object passed into grunt.initConfig().

grunt.initConfig({
  photobox: {
    task : {
      options: {
        // Task-specific options go here.
      }
    }
  },
})

Photobox helps you to not deploy any broken layout to production. It takes screenshots of you current site.

Additionally you got the feature, to keep the last photosession and to overlay old and new screenshots, to see even better if something is broken or not. BE ALWAYS SURE, THAT YOU HAVEN'T BROKEN LAYOUT THE EASY WAY.

ImageMagick and Canvas representation (generated diff):

image

Options

options.indexPath

Type: String

Default value: photobox/

A string value that is used to set the path to the generated images and index.html.

Per default a photobox folder will be generated and inside of that folder an index.html is located to check for broken layout.

options.screenSizes

Type: Array

Default value: [ '800' ]

[NOTE: Values like '800x600' are deprecated since version 0.5.0.]

An array containing strings, that represents the wished width in pixels of the taken pictures. The height will be calculated automatically depending on the given site.

E.g. '800' -> width: 800px;

options.urls

Type: Array

Default value: [ 'http://google.com' ]

An array containing strings, that represents the wished urls for the photosession.

options.relativePaths

Type: Boolean

Default value: false

If final images should contain only realative urls.

options.userName

Type: String

Default value: ``

A string representing the username in case of HTTP-Authentification.

options.password

Type: String

Default value: ``

A string representing the password in case of HTTP-Authentification.

options.template

Type: String|Object

Default value: canvas

A string value that is used to set the template to display your screenshots. Possible values:

  • canvas -> uses Canvas to show differences in screenshots.
  • magic -> uses ImageMagick to show the difference of old and new screenshots.

If you want to use ImageMagick by setting options.template to magic make sure ImageMagick and included commands are installed on your system:

Check the following commands in your environment:

$ which convert
/opt/local/bin/convert
$ which composite
/opt/local/bin/composite

If you want to pimp your via canvas generated diff images there is the option available to pass in an object as template instead of a string.

options : {
  ...
  template       : {
    name    : 'canvas',
    options : {
      highlightColor : '#0000ff',  //
      diffFilter     : 'grayscale' //  default == no filter 'grayscale' | 'darker' | 'brighter'
    }
  }
  ...
}
options.template.name

Type: String

Currently only supported set to canvas.

options.template.options.highlightColor

Type: String

Default value: '#0000ff'

A string representing a given color for highlighted different areas.

options.template.options.diffFilter

Type: String

Default value: default

4 modes for diff image processing are available:

  • default - image information in diff image will not be changed
  • grayscale - image information in diff image will be changed to grayscale
  • darker - image information in diff image will be changed to a darker image
  • brighter - image information in diff image will be change to a brighter image

+#### options.timeOut

Type: Integer

Default value: 1000

An Integer representing the delay in milliseconds after the screenshot should be taken.

Usage Examples

Default Options

In this example, the default options are used to do just show what is possible. Run grunt photobox without any custom options and you will get a new file at photobox/index.html.

It will consist of a screenshot for the default url ( http://google.com ) in the default width 800px.

grunt.initConfig( {
  photobox: {
    task: {
      options: {}
    }
  }
});

Options

Now let's customize everything for your needs.

grunt.initConfig( {
  photobox: {
    task: {
      options: {
        screenSizes : [ '600', '1000', '1200' ],
        urls        : [ 'http://yoursite.com', 'http://yoursite.com/blog', 'http://yoursite.com/catalog' ]
      }
    }
  }
} );

This will generate you 9 screenshots - each url in each size.

Canvas default usage

grunt.initConfig( {
  photobox : {
    waisenkinder : {
      options : {
        indexPath      : 'photobox/',
        highlightColor : '#0000ff',
        screenSizes    : [ '960', '350', '1200' ],
        template       : 'canvas',
        urls           : [ 'http://4waisenkinder.de' ]
      }
    }
  }
} );

Canvas configured usage

grunt.initConfig( {
  photobox : {
    waisenkinder : {
      indexPath      : 'photobox/',
      screenSizes    : [ '960', '350', '1200' ],
      template       : {
        name    : 'canvas',
        options : {
          highlightColor : '#0000ff',  // template.options.hightlightColor || highlightcolor || default
          diffFilter     : 'grayscale' //  'default' == no filter | 'grayscale' | 'darker' | 'brighter'
        }
      },
      urls           : [ 'http://4waisenkinder.de' ]
    }
  }
} );

ImageMagick usage

grunt.initConfig( {
  photobox : {
    waisenkinder : {
      options : {
        indexPath      : 'photobox/',
        screenSizes    : [ '960', '350', '1200' ],
        template       : 'magic',
        urls           : [ 'http://4waisenkinder.de' ]
      }
    }
  }
} );

Relative urls usage

grunt.initConfig( {
  photobox : {
    prod : {
      options : {
        screenSizes    : [ '480', '1200' ],
        relativePaths  : true,
        urls           : [ 'http://4waisenkinder.de' ]
      }
    },
    dev : {
      options : {
        screenSizes    : [ '480', '1200' ],
        relativePaths  : true,
        urls           : [ 'http://localhost:8080' ]
      }
    }
  }
} );

If the localhost:8080 and 4waisenkinder.de are the same pages, we can easily now compare them by running: ['photobox:prod', 'photobox:dev'] as the images will have relative paths names.

Contributing

In lieu of a formal styleguide, take care to maintain the existing coding style. Add unit tests for any new or changed functionality. Lint and test your code using Grunt.

Donating

Support this project and others by stefanjudis via gittip.

Support via Gittip

Release History

Please check release history at Github. :)

Bitdeli Badge

grunt-photobox's People

Contributors

a-ursino avatar bitdeli-chef avatar chaeringer avatar danielhusar avatar davidlinse avatar sbmadhav avatar stefanjudis avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

grunt-photobox's Issues

Photobox with connect or express server

I've been trying to implement grunt-photobox on a current project and cannot seem to get it to generate the photobox directory. Before implementing a local server I ran the grunt photobox task and it generated the photobox directory with the img > last directory and created an index.html page showing diffs and kittens, but since implementing a server I cannot get the task to produce any results. The terminal output upon running the photobox task is

Done, without errors.

I've tried implementing this in a local environment running both an express and connect server. Essentially, I have tried running the server in one terminal tab and in another tab running the photobox grunt task from within the repo. Here are examples

Connect:
https://github.com/dtothefp/grunt-photobox-connect

Express:
https://github.com/dtothefp/grunt-photobox-express

-- In both cases a watch is setup on the main.css file to run the photobox task upon any change.

Photo session not working on windows

I'm getting the following error during grunt build:

‘Takin’ picture of http://4waisenkinder.de|800x600 did not work correctly…
Error: ‘800x600’ is not recognized as an internal or external command, operable program or batch file.’

Here are my specs:

OS: Windows 7
Grunt-cli v0.1.9
Grunt v0.4.1
PhantomJS v1.9.2
NodeJS v.0.10.21
Grunt-photobox v0.4.3

Running PhantomJS off a exe in C:\bin. I've got karma working fine with PhantomJS so I dont think it is a PhantomJS issue

Not Able to install plug-in on MAC

Hi @stefanjudis ,

When I try to install this plug-in on my machine it doesn't work and just to update you I am running on Node 5.6.0 while NPM version is 3.6.0. Is there something that I need to install first before installing this plug-in?

It starts breaking with below errors:
CXX(target) Release/obj.target/bufferutil/src/bufferutil.o
In file included from ../src/bufferutil.cc:16:
../../nan/nan.h:261:25: error: redefinition of '_NanEnsureLocal'
NAN_INLINE v8::Local _NanEnsureLocal(v8::Local val) {
^
../../nan/nan.h:256:25: note: previous definition is here
NAN_INLINE v8::Local _NanEnsureLocal(v8::Handle val) {
.....
.....

Any help will be appreciated.

Thanks
Vikash Bhardwaj

Multitask

I would like to define different tasks for production and testing environments...

Colon in filenames

There appears to be an issue when the URL contains a colon, such as "http://localhost:8888/".
The colon remains in the filename and in the command line parameters to ImageMagick. This causes problems, at least on Windows.

PHOTOBOX STARTED PHOTO SESSION.
started photo session for http://localhost:8888/#960
>> picture of http://localhost:8888/#960 taken.
>> PHOTOBOX FINISHED PHOTO SESSION SUCCESSFULLY.

NOTE: You defined to use ImageMagick, make sure it is installed.

PHOTOBOX STARTED DIFF GENERATION.
started diff for localhost:8888--960
>> Error: composite.EXE: unable to open image `8888--960.png': No such file or directory @ error/blob.c/OpenBlob/2657.
>> composite.EXE: unable to open file `8888--960.png' @ error/png.c/ReadPNGImage/4021.
>> composite.EXE: unable to open image `8888--960.png': No such file or directory @ error/blob.c/OpenBlob/2657.
>> composite.EXE: unable to open file `8888--960.png' @ error/png.c/ReadPNGImage/4021.
>> composite.EXE: missing an image filename `photobox/img/diff/localhost:8888--960-diff.png' @ error/composite.c/CompositeImageCommand/1613.
>> Error: convert.EXE: unable to open image `8888--960-diff.png': No such file or directory @ error/blob.c/OpenBlob/2657.
>> convert.EXE: unable to open file `8888--960-diff.png' @ error/png.c/ReadPNGImage/4021.
>> convert.EXE: no images defined `photobox/img/diff/localhost:8888--960.png' @ error/convert.c/ConvertImageCommand/3187.
>> PHOTOBOX FINISHED DIFF GENERATION SUCCESSFULLY.

PHOTOBOX STARTED INDEX FILE GENERATION
>> PHOTOBOX CREATED NEW 'index.html' AT 'photobox/'.

SSL pages issue

Hi,

thanks a lot for this task its amazing :)

I noticed that it doesn't work with some ssl pages, its a phantomjs issue, and when you pass --ssl-protocol=any it works fine.

Do you think you can implement this flag in your script as well?

Thanks :)

Implement slimer.js

It would be nice to not only cover webkit with phantom.js... For that reason check out slimer if it could work with it.

Split photobox to another library

I would like to use the methods available in tasks/lib/photobox.js and import it as it is now used via tasks/photobox.js Grunt task.

Any plans on separating the two, perhaps as node-photobox and grunt-photobox, essentially having the non Grunt parts in the first?

Screenshots do not show all elements

Hi Stefan,

I love photobox and it works in 9 out of 10 cases for me. However, there are a few pages that may take a few milliseconds longer to load because they are doing javascript'ish things with photos such as using Foundation's Interchange. As a result, those photos are not displayed in the output files consistently.

Would there be a way to include a "delay" option that tells the task how long to wait for the page to load before taking the screenshot?

Make the differences a bit clear

In the canvas diff would be great to have the background a little bit white transparency and the differences in red.

This should be in a config file that you can choose if you want background, whats the transparency and whats the color of diff.

Problem with pipe char on windows

Hi
when i try to launch grunt-photobox on win7 machine with this configuration

    photobox : {
        waisenkinder : {
          options : {
            indexPath      : 'photobox/',
            highlightColor : '#0000ff',
            template       : 'canvas',
            urls           : [ 'http://4waisenkinder.de' ]
          }
        }
    },

i got the following error

started photo session for http://4waisenkinder.de|800
Command: phantomjs ..\node_modules\grunt-photobox\tasks\lib\photoboxScript.js http://4waisenkinder.de|800 photobox/ photobox/options.json

'800' is not recognized as an internal or external command, operable program or batch file.
Takin' picture of http://4waisenkinder.de|800did not work correclty...

Error
PhotoSessionCallback: Result for http://4waisenkinder.de|800 was
PhotoSessionCallback: Code for http://4waisenkinder.de|800 was 255

i think that the problem is with pipe char on windows

any suggestion?

thanks

Diff not working in dev-master with imagemagick

It is working with 0.6.0. old images are also there, so running photobox several times does not fix issue.

Running "photobox:task" (photobox) task

PHOTOBOX STARTED PHOTO SESSION.
started photo session for http://com#1200
started photo session for https://com/login#1200
>> picture of login#1200 taken.
>> picture of http://com#1200 taken.
>> PHOTOBOX FINISHED PHOTO SESSION SUCCESSFULLY.

NOTE: You defined to use ImageMagick, make sure it is installed.

PHOTOBOX STARTED DIFF GENERATION.
started diff for .com#1200
>> Nothing to diff here - no old pictures available.
started diff for com-login#1200
>> Nothing to diff here - no old pictures available.
>> PHOTOBOX FINISHED DIFF GENERATION SUCCESSFULLY.

PHOTOBOX STARTED INDEX FILE GENERATION
>> PHOTOBOX CREATED NEW 'index.html' AT 'data/photobox/'.

Done, without errors.

Historical Diffs

Hi,

Observed:
You can only make a diff between the last 2 screenshots.

Desired:
Two drop-downs or datepickers where you can select which screenshots you want to compare.

I would really love to see this feature.

Only show screenshots when there are differences (optional)

It would be nice to have the option to only show the screenshots on the summary page if they are different. For other cases it could show "No differences detected".

This should be configurable.

The benefit is that you filter out the irrelevant screenshots.

Comparing 2 domains

So I am intrigued with this:

If the localhost:8080 and 4waisenkinder.de are the same pages, we can easily now compare them by running: ['photobox:prod', 'photobox:dev'] as the images will have relative paths names.

However, there is no clarification to how I can actually use this. Where do I stick this?

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.