image2tiles

package module
v0.0.4 Latest Latest
Warning

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

Go to latest
Published: May 4, 2022 License: MIT Imports: 12 Imported by: 0

README

image2tiles

GoDoc Go Report Card

image2tiles is a tool to cut large image into square tiles, to be used for a interactive tiled viewer.

There are many high-performant viewing of large image available,but cropping and slicing images may be trouble. image2tiles support custom tile size and creates all tiles to be used by map tool like leaflet, openlayers or Other.

Command Line

How to get
Download

You can download from GitHub releases.

For example download file:

  • windows: **_windows_x86_64.zip
  • maxOS x86: **_darwin_x86_64.tar.gz
  • maxOS M1: **_darwin_arm64.tar.gz
Build from source
git clone https://github.com/lvisei/image2tiles
cd cmd/image2tiles && go install
Usage
image2tiles -f image.png -s 512

Options flags:

image2tiles

Usage: image2tiles -f <filename> [-s] [-t] [-b] [-o]

Options:
  -b string
        The background color to be used for the tiles (default "#ffffff00")
  -f string
        Image filename to be convert
  -o string
        Output file pattern (default "out/%d/%d-%d.jpg")
  -s int
        The tile height/width (default 512)

Library

How to get
go get github.com/lvisei/image2tiles
Usage

Image into small single tile

package main

import (
	"fmt"
	"github.com/lvisei/image2tiles"
)

func main() {
  converter := image2tiles.NewConverter()

  if err := converter.Prepare("image.png", "#fff"); err != nil {
      fmt.Println(err)
  }

  if img, err := converter.Tile(0, [2]int{256, 256}, [2]int{0, 0}, true); err!=nil {
  	fmt.Println(err)
  }else {
  	image2tiles.SaveJPG("out/0-0-0.jpg", img, 75)
  }
}

Image into multiple small tiles

package main

import (
	"fmt"
	"github.com/lvisei/image2tiles"
)

func main() {
  converter := image2tiles.NewConverter()

  if err := converter.Prepare("image.png", "#00000000"); err != nil {
      fmt.Println(err)
  }

  if err := converter.Execute([2]int{256, 256}, true, 75, "out/level-%d/%d-%d.jpg"); err != nil {
  	fmt.Println(err)
  }

  fmt.Println(converter.MaxZoom, converter.TileSize)
}

LICENSE

MIT

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ImageToRGBA

func ImageToRGBA(src image.Image) *image.RGBA

func LoadImage

func LoadImage(path string) (image.Image, error)

func LoadPNG

func LoadPNG(path string) (image.Image, error)

func ParseHexColor

func ParseHexColor(x string) color.RGBA

func SaveJPG

func SaveJPG(path string, im image.Image, quality int) error

func SavePNG

func SavePNG(path string, im image.Image) error

Types

type Converter

type Converter struct {
	Image               image.Image
	ImageWidth          int
	ImageHeight         int
	OriginalImageWidth  int
	OriginalImageHeight int
	MaxZoom             int
	TileSize            [2]int
}

func NewConverter

func NewConverter() *Converter

func (*Converter) Execute

func (converter *Converter) Execute(size [2]int, efficient bool, imageQuality int, output string) error

Execute a large image into small tiles

func (*Converter) Prepare

func (converter *Converter) Prepare(imageName string, bgColor string) error

Prepare a large image for tiling

func (*Converter) Tile

func (converter *Converter) Tile(level int, size [2]int, quadrant [2]int, efficient bool) (image.Image, error)

Tile Extract a single tile from a larger image

Directories

Path Synopsis
cmd

Jump to

Keyboard shortcuts

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