picasso

package module
v0.0.0-...-030fc7f Latest Latest
Warning

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

Go to latest
Published: Sep 29, 2015 License: MIT Imports: 5 Imported by: 10

README

Picasso, a Go image composer

Build Status Coverage GoDoc

Example

Manual layout handling

The following code:

image := picasso.HorizontalSplit{
	Ratio: 2,
	Top:   picasso.Picture{bullfight},
	Bottom: picasso.VerticalSplit{
		Ratio: 0.5,
		Left:  picasso.Picture{girlBeforeAMirror},
		Right: picasso.VerticalSplit{
			Ratio: 1,
			Left:  picasso.Picture{oldGuitarist},
			Right: picasso.Picture{womenOfAlgiers},
		},
	},
}.Draw(400, 600)

Will compose the following image:

manual

Automatic layouts

Picasso also supports different automatic layouts and borders, so that the following code:

images := []image.Image{
	girlBeforeAMirror,
	oldGuitarist,
	womenOfAlgiers,
	bullfight,
	weepingWoman,
	laReve,
}
layout := picasso.GoldenSpiralLayout()
gray := color.RGBA{0xaf, 0xaf, 0xaf, 0xff}
image := layout.Compose(images).DrawWithBorder(600, 600, gray, 2)

Will compose an image using the golden ratio:

automatic

Or one could use the GridLayout:

images := []image.Image{...}
gray := color.RGBA{0xaf, 0xaf, 0xaf, 0xff}
image := picasso.DrawGridLayoutWithBorder(images, 800, gray, 2)

to compose larger sets of images:

composed

See tests for more examples

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func DrawGridLayout

func DrawGridLayout(images []image.Image, width int) image.Image

DrawGridLayout draws an image composed into a grid layout. The layout will coerce all provided images into either a portrait or a landscape picture with an aspect ratio of sqrt(2) (or sqrt(2) and 1/sqrt(2) to be precise). The composed image will also have the same aspect ratio. This allows indefinitely splitting the composed image into halves while maintaining the same aspect ratios for all parts.

To enforce an aspect ratio on the resulting image, the interface allows one to only specify the width. The height of the resulting image will be either width/sqrt(2) if it's in landscape or width*sqrt(2) if it's in portrait. The orientation of the resulting image depends on the orientation of the provided images that it will be composed of.

This layout is not able to manage some combinations of orientations of the provided images. For the example, it has now way to compose a single portrait and a single landscape image. In these cases, the layout will simply discard the last image in the list.

func DrawGridLayoutWithBorder

func DrawGridLayoutWithBorder(images []image.Image, width int, borderColor color.Color, borderWidth int) image.Image

DrawGridLayoutWithBorder does the exact same thing that DrawGridLayout does, but with borders.

Types

type HorizontalSplit

type HorizontalSplit struct {
	Top    Node
	Bottom Node
	Ratio  float32
}

func (HorizontalSplit) Draw

func (n HorizontalSplit) Draw(width, height int) image.Image

func (HorizontalSplit) DrawWithBorder

func (n HorizontalSplit) DrawWithBorder(width, height int, borderColor color.Color, borderWidth int) image.Image

type Layout

type Layout interface {
	Compose([]image.Image) Node
}

func GoldenSpiralLayout

func GoldenSpiralLayout() Layout

GoldenSpiralLayout will create a layout that creates splits following a golden spiral that starts moving to the right and to the bottom (the most common version).

func TopHeavyLayout

func TopHeavyLayout() Layout

TopHeavyLayout creates a layout that works well for up to 4 images with a landscape aspect ratio. In this layout, 2 images are shown with equal sizes one atop the other. With 3 images the bottom part will get split in half and 2 images will be fit into that part side by side. With 4 and more images, the first image will be on top and rest of the images will be on a single row below, all with equal widths. Also, with 4 and more images, the top part's height will be 2 times that of the bottom one.

type Node

type Node interface {
	Draw(width, height int) image.Image
	DrawWithBorder(width, height int, borderColor color.Color, borderWidth int) image.Image
}

type Picture

type Picture struct {
	Picture image.Image
}

func (Picture) Draw

func (n Picture) Draw(width, height int) image.Image

func (Picture) DrawWithBorder

func (n Picture) DrawWithBorder(width, height int, borderColor color.Color, borderWidth int) image.Image

type VerticalSplit

type VerticalSplit struct {
	Left  Node
	Right Node
	Ratio float32
}

func (VerticalSplit) Draw

func (n VerticalSplit) Draw(width, height int) image.Image

func (VerticalSplit) DrawWithBorder

func (n VerticalSplit) DrawWithBorder(width, height int, borderColor color.Color, borderWidth int) image.Image

Jump to

Keyboard shortcuts

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