InfoHeap
Tech
Navigation
  • Home
  • Tutorials
    • CSS tutorials & examples
    • CSS properties
    • Javascript cookbook
    • Linux/Unix Command Line
    • Mac
    • PHP
      • PHP functions online
      • PHP regex
    • WordPress
  • Online Tools
    • Text utilities
    • Online Lint Tools
search

PhantomJS tutorials

  • Install phantomjs on Mac
  • Install phantomjs on Ubuntu
  • create site snapshot thumbnail
  • find all fonts-families on a web page
  • print resources request by a page
  • skip Google analytics when fetching a web page
 
  • Home
  • > Tutorials
  • > Javascript
  • > PhantomJS

How to use phantomjs to create site/url snapshot thumbnail

By admin | Last updated on Jun 6, 2020

PhantomJS in a scriptable webkit written by Ariya Hidayat. Chrome and Safari are based on webkit. This is the formal definition as per the official site:

PhantomJS is a headless WebKit scriptable with a JavaScript API. It has fast and native support for various web standards: DOM handling, CSS selector, JSON, Canvas, and SVG.

There are lots of things which can be done with PhantomJS including testing,  automation, etc. This article I’ll create a screenshot of a web page and resize it to a thumbnail. I’m using Mac for creating the thumbnail, but you should be able to use Ubuntu or any other Linux as well.

Installing PhantomJS

  • Mac: how to install phantomjs on Mac
  • Ubuntu: How to install phantomjs on Ubuntu Linux

Capture screen from url

Here is the code which opens a webpage and renders it to a png img. This code snippet based on example code from github phantonjs page. Save the following code to a file screen_capture.js and replace the url with the url you want to capture.

var page = require('webpage').create();
page.viewportSize = { width: 1024, height: 768 };
page.open('https://infoheap.com/', function () {
  page.clipRect = {top:0, left:0, width:1024, height:1024};
  page.render('site.png');
  phantom.exit();
});

Here is the command to run it:

phantomjs screen_capture.js

This will create site.png image.

Resize the image using convert

Use command line utility convert to resize the image. Here is the command:

convert site.png -resize 100x100 site_thumbnail.png

Here is the outcome for url https://infoheap.com/:
infoheap-site-thumbnail

Suggested posts:

  1. How to install phantomjs on Mac
  2. How to install node (node.js) on Mac
  3. How to edit animated gif speed (FPS) using imagemagick convert
  4. How to install and run Chrome PageSpeed insights for measuring site performance
  5. Chrome memory usage – some tips to keep it under control
  6. WordPress how to check if a post is being viewed by admin
  7. Find used ports by an app on Android using Adb
  8. Gmail – how to send email from different address
Share this article: share on facebook share on linkedin tweet this submit to reddit
Posted in Tutorials | Tagged Javascript, Linux, Mac, PhantomJS, Tutorials
  • Browse content
  • Article Topics
  • Article archives
  • Contact Us
Popular Topics: Android Development | AngularJS | Apache | AWS and EC2 | Bash shell scripting | Chrome developer tools | Company results | CSS | CSS cookbook | CSS properties | CSS Pseudo Classes | CSS selectors | CSS3 | CSS3 flexbox | Devops | Git | HTML | HTML5 | Java | Javascript | Javascript cookbook | Javascript DOM | jQuery | Kubernetes | Linux | Linux/Unix Command Line | Mac | Mac Command Line | Mysql | Networking | Node.js | Online Tools | PHP | PHP cookbook | PHP Regex | Python | Python array | Python cookbook | SEO | Site Performance | SSH | Ubuntu Linux | Web Development | Webmaster | Wordpress | Wordpress customization | Wordpress How To | Wordpress Mysql Queries | InfoHeap Money

Copyright © 2025 InfoHeap.

Powered by WordPress