Help us shape the future of Go! Take the 2026 Go Developer Survey

sshot

package module
v0.0.0-...-815d538 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 21, 2018 License: MIT Imports: 6 Imported by: 0

README

Pageres Go Wrapper

Build Status Go Report Card

Golang package for capturing screenshots of websites in various resolutions. It uses Pageres https://github.com/sindresorhus/pageres-cli internally.

Installation

$ npm install --global pageres-cli
$ go get -u github.com/slotix/pageres-go-wrapper

Usage

package main
import (
    "fmt"
    "os"
	sshot "github.com/slotix/pageres-go-wrapper"
)

func main() {
    shotsDir := "shots"
    os.Mkdir(shotsDir, 0777)
	params := sshot.Parameters{
		Command: "pageres",
		Sizes:   "1024x768",
		Crop:    "--crop",
		Scale:   "--scale 0.9",
		Timeout: "--timeout 30",
		Filename:  fmt.Sprintf("--filename=%s/<%%= url %%>", shotsDir),
		UserAgent: "",
	}
	urls := []string{
		"http://google.com",
		"https://dbconvert.com",
		"http://something-that-doesnot-exists.com",
	}
	sshot.GetShots(urls, params)
	sshot.DeleteZeroLengthFiles(shotsDir)
}

Find more information about parameters at https://github.com/sindresorhus/pageres

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func DeleteZeroLengthFiles

func DeleteZeroLengthFiles(dir string)

DeleteZeroLengthFiles deletes zero length files from a specified dir

func GetShots

func GetShots(urls []string, params Parameters)

GetShots starts pageres process itself and returns URL if Pageres Couldn't load url. Empty string is returned overwise

Types

type Parameters

type Parameters struct {
	Command   string
	Sizes     string //Use a <width>x<height> notation or a keyword.
	Crop      bool   //Crop to the set height. add --crop to args if set to true
	Scale     string //Scale webpage n times.
	Timeout   string //Number of seconds after which PhantomJS aborts the request.
	Filename  string //Define a customized filename. For example <%= date %> - <%= url %>-<%= size %><%= crop %>.
	UserAgent string //Custom user agent.
	Format    string //Image format: png or jpg
	Overwrite bool   //Will overwrite existing screenshot file if set to true
}

Parameters struct serves for passing parameters for pageres Read more information about parameters at https://github.com/sindresorhus/pageres

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL