Giter Site home page Giter Site logo

heimdall's Introduction

Introduction

Heimdall is a python library that makes it very straightforward to quickly and easily create screenshots from web pages:

heimdall.png("https://www.distilled.net/", device="Kindle Fire")

Heimdall knows about lots of common devices, and can simulate them (their resolution and user agent) when you request a screenshot. For example, you could take a screenshot as an original iPad might see a page. However, you can also specify resolution and user agent yourself.

You can also specify what format you'd like the output in, and whether you want to crop the image based on the display size, or if you would rather get the whole webpage.

NOTE: Heimdall uses PhantomJS and as such does not fully support device-pixel-ratio for emulating devices with hige density displays - this doesn't seem to matter for most purposes but you should be aware. There is a $1000 bounty for anyone who can get the functionality added to PhantomJS.

Installing Heimdall

Firstly, you need to install phantomjs:

npm install phantomjs

If you get any problems try: npm install -g phantomjs

Then simply install Heimdall via pip:

pip install heimdall

You should now be good to go.

Using Heimdall

Quick and easy:

from heimdall import heimdall

heimdall.png("https://www.distilled.net/", device="Kindle Fire")
heimdall.jpeg("https://www.facebook.com/", device="iPhone") # Will use iPhone 6
heimdall.pdf("http://news.ycombinator.com", device="iPhone 3") # Specify a device version
heimdall.pdf("https://twitter.com/", device="Laptop")

heimdall.png("https://github.com/", crop_to_visible=True) # Crop the image
heimdall.png("http://www.tomanthony.co.uk/", width=1440, height=900) # Specify own display size

You can get information about the screenshot you took:

screenshot = heimdall.png("https://www.distilled.net/", width=1440, height=900)

screenshot.filename # www_distilled_net.png
screenshot.path # /tmp/www_distilled_net.png
screenshot.directory # /tmp
screenshot.ext # png

If you want to would like to pass the file type in as a parameter for whatever reason, then that is easy:

heimdall.save("https://www.distilled.net/", format="PNG", device="Galaxy S3")

You can specify an optimize flag should you want the image optimized on save:

heimdall.png("https://www.distilled.net/", optimize=True , device="Galaxy S3")

To Do

  • It would be nice to resolve the device-pixel-ratio issue. PhantomJS is moving from QtWebKit to a Blink based engine, so hopefully we will see this resolved down the line.
  • renderafter functionality to wait a certain amount of time before screenshotting

Why Heimdall?

Heimdall is the all seeing god of Norse mythology, and this was a hackday project so we got stuck there. :)

Thanks

We are using Johan Dahlberg's fantastic optparse-js library.

Thanks to Raphaël Goetter for (http://mydevice.io/), which we used to get some device resolutions.

Contributing

See CONTRIBUTING file.

License

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License

See LICENSE file.

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.