wkhtmltoimage

package module
v0.0.0-...-6d096fe Latest Latest
Warning

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

Go to latest
Published: Nov 25, 2021 License: MIT Imports: 7 Imported by: 0

README

go-wkhtmltoimage

GoDoc Build Status

go wrapper around wkhtmltoimage.

Not production ready.

Install

go-wkhtmltoimage
go get github.com/ninetwentyfour/go-wkhtmltoimage
wkhtmltoimage

Install by hand: http://wkhtmltopdf.org/downloads.html

Examples

Get url and save image yourself.

package main

import (
  "fmt"
  "github.com/ninetwentyfour/go-wkhtmltoimage"
  "os"
)

func main() {
  c := wkhtmltoimage.ImageOptions{Input: "http://example.com", Format: "png"}
  out, _ := wkhtmltoimage.GenerateImage(&c)
  f, _ := os.Create("/tmp/example.png")
  defer f.Close()
  n2, _ := f.Write(out)
  fmt.Printf("wrote %d bytes\n", n2)
}

Load a file and auto save the result

package main

import (
  "github.com/ninetwentyfour/go-wkhtmltoimage"
)

func main() {
  c := wkhtmltoimage.ImageOptions{Input: "/tmp/example.html", Format: "png", Output: "/tmp/example.png"}
  wkhtmltoimage.GenerateImage(&c)
}

Save html string to image

package main

import (
  "github.com/ninetwentyfour/go-wkhtmltoimage"
)

func main() {
  html := "<html><head></head><body><p style='color:red;'>example</p></body></html>"
  c := wkhtmltoimage.ImageOptions{Input: "-", Format: "png", Output: "/tmp/example.png", Html: html}
  wkhtmltoimage.GenerateImage(&c)
}

Contributing:

  1. Fork it
  2. Create your feature branch (git checkout -b my-new-feature)
  3. Commit your changes (git commit -am 'Add some feature')
  4. Push to the branch (git push origin my-new-feature)
  5. Create new Pull Request

Documentation

Overview

Package wkhtmltoimage provides a simple wrapper around wkhtmltoimage (http://wkhtmltopdf.org/) binary.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func GenerateImage

func GenerateImage(options *ImageOptions) ([]byte, error)

GenerateImage creates an image from an input. It returns the image ([]byte) and any error encountered.

Types

type ImageOptions

type ImageOptions struct {
	// BinaryPath the path to your wkhtmltoimage binary. REQUIRED
	//
	// Must be absolute path e.g /usr/local/bin/wkhtmltoimage
	BinaryPath string
	// Input is the content to turn into an image. REQUIRED
	//
	// Can be a url (http://example.com), a local file (/tmp/example.html), or html as a string (send "-" and set the Html value)
	Input string
	// Format is the type of image to generate
	//
	// jpg, png, svg, bmp supported. Defaults to local wkhtmltoimage default
	Format string
	// Height is the height of the screen used to render in pixels.
	//
	// Default is calculated from page content. Default 0 (renders entire page top to bottom)
	Height int
	// Width is the width of the screen used to render in pixels.
	//
	// Note that this is used only as a guide line. Default 1024
	Width int
	// Quality determines the final image quality.
	//
	// Values supported between 1 and 100. Default is 94
	Quality int
	// Html is a string of html to render into and image.
	//
	// Only needed to be set if Input is set to "-"
	Html string
	// Output controls how to save or return the image.
	//
	// Leave nil to return a []byte of the image. Set to a path (/tmp/example.png) to save as a file.
	Output string
}

ImageOptions represent the options to generate the image.

Jump to

Keyboard shortcuts

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