gosaic

package module
v0.0.0-...-3e51125 Latest Latest
Warning

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

Go to latest
Published: Aug 27, 2018 License: Apache-2.0 Imports: 23 Imported by: 0

README

gochallenge3

This is my entry for the Go Challenge 3 contest:

  • create a program that creates mosaics (images pieced together from many smaller images)
  • create program for searching an image database (Instagram)
  • combine them to produce a webapp

logo

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ComputeAverageColor

func ComputeAverageColor(img image.Image) color.RGBA

func Download

func Download(urls []ImageURL, downloadDir string, maxConcurrency int) ([]string, error)

Downloads the images to the download directory, using goroutines for concurrency. NB: to avoid overwhelming image servers, best to keep maxConcurrency <= 10. This also prevents "dial tcp: no such host" errors on OSX due to file descriptors maxing out.

func SavePng

func SavePng(img image.Image, outfile string) error

func Scale

func Scale(srcImg image.Image, r image.Rectangle) image.Image

Scale scales the src image to the given rectangle using Nearest Neighbor

func ScaleToFile

func ScaleToFile(srcPath, dstPath string, r image.Rectangle) error

func Serve

func Serve(addr, uploadRootDir string, imageSource *InstagramClient)

func SplitPath

func SplitPath(path string) []string

func ToRows

func ToRows(rowLen int, imageURLs []ImageURL) [][]ImageURL

Types

type ImageURL

type ImageURL string

type InstagramClient

type InstagramClient struct {
	ClientID string
}

simple client for the Instagram Search API

func (*InstagramClient) Search

func (i *InstagramClient) Search(s string, maxResults int) ([]ImageURL, error)

type InstagramData

type InstagramData struct {
	Tags     []string          `json:"tags"`
	ImageSet InstagramImageSet `json:"images"`
}

type InstagramImage

type InstagramImage struct {
	Url    string `json:"url"`
	Width  int32  `json:"width"`
	Height int32  `json:"height"`
}

type InstagramImageSet

type InstagramImageSet struct {
	LowRes      InstagramImage `json:"low_resolution"`
	Thumb       InstagramImage `json:"thumbnail"`
	StandardRes InstagramImage `json:"standard_resolution"`
}

type InstagramPagination

type InstagramPagination struct {
	MaxTagID string `json:"max_tag_id"`
	MinTagID string `json:"min_tag_id"`
	NextURL  string `json:"next_url"`
}

type InstagramResponse

type InstagramResponse struct {
	Pagination InstagramPagination `json:"pagination"`
	Data       []InstagramData     `json:"data"`
}

func ParseInstagramJSON

func ParseInstagramJSON(jsonBytes []byte) (InstagramResponse, error)

type Mosaic

type Mosaic struct {
	TileW int
	TileH int
	// contains filtered or unexported fields
}

func NewMosaic

func NewMosaic(tileW, tileH int, tileImageFiles []string) Mosaic

func (*Mosaic) Generate

func (m *Mosaic) Generate(sourceImageFile, outfile string, widthMult, heightMult int) error

type Page

type Page struct {
	Title    string
	UploadID string
	Project  *Project

	Error error
	// contains filtered or unexported fields
}

type Project

type Project struct {
	ID string

	Status
	// contains filtered or unexported fields
}

Project represents a mosaic project- the uploaded file, selected tile images, and resulting mosaic image

func NewProject

func NewProject(uploadRootDir string) (*Project, error)

func ReadProject

func ReadProject(uploadRootDir, id string) (*Project, error)

func (*Project) GeneratedMosaicFile

func (p *Project) GeneratedMosaicFile() string

func (*Project) ImageUrlsFile

func (p *Project) ImageUrlsFile() string

func (*Project) LoadStatus

func (p *Project) LoadStatus() error

func (*Project) ReceiveUpload

func (p *Project) ReceiveUpload(r io.Reader) error

func (*Project) SetAndSaveStatus

func (p *Project) SetAndSaveStatus(status Status) error

func (*Project) Thumbnails

func (p *Project) Thumbnails() ([]string, error)

func (*Project) ThumbnailsDir

func (p *Project) ThumbnailsDir() string

func (*Project) ToFile

func (p *Project) ToFile(urls []ImageURL) error

func (*Project) UploadedImageDir

func (p *Project) UploadedImageDir() string

func (*Project) UploadedImageFile

func (p *Project) UploadedImageFile() string

type Status

type Status string
const (
	StatusNew         Status = "new"
	StatusSearching   Status = "searching images"
	StatusDownloading Status = "downloading images"
	StatusGenerating  Status = "generating mosaic"
	StatusError       Status = "error"
	StatusCompleted   Status = "completed"
)

type Tile

type Tile struct {
	ScaledImage  image.Image
	AverageColor color.RGBA
}

Tile is an image scaled to fit a given rectangle, along with its computed average color.

func NewTile

func NewTile(sourceImageFile string, r image.Rectangle) (*Tile, error)

func (*Tile) GoString

func (t *Tile) GoString() string

Directories

Path Synopsis
commands
app command
App is a web server that allows users to upload images and turn them into mosaics.
App is a web server that allows users to upload images and turn them into mosaics.
instafetch command
Fetches tagged images from Instagram
Fetches tagged images from Instagram
mosaic command

Jump to

Keyboard shortcuts

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