adapt

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Oct 1, 2022 License: MIT Imports: 6 Imported by: 0

Documentation

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

func Thumbnail

func Thumbnail(pc *types.Postcard, maxWidth, maxHeight int) (image.Image, error)

Thumbnail generates a thumbnail image representing this postcard's front. Providing a maximum width or height of zero will allow the thumbnail to grow up to the postcard's original size in that dimension.

func ThumbnailFile

func ThumbnailFile(path string, maxWidth, maxHeight int) (image.Image, error)

ThumbnailFile is a convenience method for retrieving a thumbnail directly on a file using Thumbnail.

Example
package main

import (
	"bytes"
	"crypto/md5"
	"fmt"
	"image/png"

	"github.com/dotpostcard/postcards-go/adapt"
)

func main() {
	thumb, err := adapt.ThumbnailFile("../fixtures/hello.postcard", 128, 0)
	if err != nil {
		panic(err)
	}

	buf := new(bytes.Buffer)
	if err := png.Encode(buf, thumb); err != nil {
		panic(err)
	}

	fmt.Printf("Thumbnail PNG (%dx%d) has checksum %x",
		thumb.Bounds().Dx(), thumb.Bounds().Dy(), md5.Sum(buf.Bytes()))
}
Output:

Thumbnail PNG (128x157) has checksum eba1acbde60137aff808c9783c05706d

Types

This section is empty.

Jump to

Keyboard shortcuts

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