Skip to content

Commit

Permalink
feat: support background transparency (#4)
Browse files Browse the repository at this point in the history
  • Loading branch information
lvisei authored Apr 29, 2022
1 parent 8205c18 commit c129408
Show file tree
Hide file tree
Showing 349 changed files with 161 additions and 45 deletions.
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -20,5 +20,5 @@

out
image2tiles
!image2tiles
!image2tiles/

18 changes: 11 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,13 @@
# image2tiles

[![GoDoc](https://godoc.org/github.com/lvisei/image2tiles?status.svg)](https://pkg.go.dev/github.com/lvisei/image2tiles)
[![Go Report Card](https://goreportcard.com/badge/github.com/lvisei/image2tiles)](https://goreportcard.com/report/github.com/lvisei/image2tiles)
[![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)

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](https://lvisei.github.io/image2tiles/leaflet.html), [openlayers](https://lvisei.github.io/image2tiles/openlayers.html) or Other.

## Command Line

### How to get
Expand Down Expand Up @@ -38,7 +44,7 @@ Usage: image2tiles -f <filename> [-s] [-t] [-b] [-o]
Options:
-b string
The background color to be used for the tiles (default "#FFF")
The background color to be used for the tiles (default "#ffffff00")
-f string
Image filename to be convert
-o string
Expand All @@ -57,7 +63,7 @@ go get github.com/lvisei/image2tiles

### Usage

Image into small single tiles
Image into small single tile

```go
package main
Expand All @@ -70,7 +76,7 @@ import (
func main() {
converter := image2tiles.NewConverter()

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

Expand All @@ -83,7 +89,7 @@ func main() {

```

Image into small multiple tiles
Image into multiple small tiles

```go
package main
Expand All @@ -96,7 +102,7 @@ import (
func main() {
converter := image2tiles.NewConverter()

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

Expand All @@ -109,8 +115,6 @@ func main() {

```



## LICENSE

[MIT](./LICENSE)
2 changes: 1 addition & 1 deletion cmd/image2tiles/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ var (
imageFilename = flag.String("f", "", "Image file name")
tileSize = flag.Int("s", 512, "The tile height/width")
output = flag.String("o", "out/%d/%d-%d.jpg", "Output file pattern")
backgroundColor = flag.String("b", "#FFF", "The background color to be used for the tiles")
backgroundColor = flag.String("b", "#ffffff00", "The background color to be used for the tiles")
)

func main() {
Expand Down
35 changes: 35 additions & 0 deletions docs/leaflet.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<title>leaflet</title>
<link
rel="stylesheet"
href="https://cdn.jsdelivr.net/npm/leaflet@1.8.0/dist/leaflet.css"
/>
<style>
* {
margin: 0;
padding: 0;
}
#map {
width: 100%;
height: 100vh;
}
</style>
<script src="https://cdn.jsdelivr.net/npm/leaflet@1.8.0/dist/leaflet-src.min.js"></script>
</head>
<body>
<div id="map"></div>
<script type="text/javascript">
const map = L.map("map", {
crs: L.CRS.Simple,
attributionControl: false,
});

map.setView([-130, 130], 3);

L.tileLayer("tiles/{z}/{x}-{y}.png", { maxZoom: 4 }).addTo(map);
</script>
</body>
</html>
53 changes: 53 additions & 0 deletions docs/openlayers.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<title>openlayers</title>
<link
rel="stylesheet"
href="https://cdn.jsdelivr.net/gh/openlayers/openlayers.github.io@master/en/v6.14.1/css/ol.css"
type="text/css"
/>
<style>
* {
margin: 0;
padding: 0;
}
#map {
width: 100%;
height: 100vh;
}
</style>
<script src="https://cdn.jsdelivr.net/gh/openlayers/openlayers.github.io@master/en/v6.14.1/build/ol.js"></script>
</head>
<body>
<div id="map"></div>
<script type="text/javascript">
const source = new ol.source.Zoomify({
url: "tiles/{z}/{x}-{y}.png?",
size: [8192, 8192],
zDirection: -1, // Ensure we get a tile with the screen resolution or higher
tileSize: 512, // from a higher zoom level
});
const extent = source.getTileGrid().getExtent();

const layer = new ol.layer.Tile({
source: source,
});

const map = new ol.Map({
layers: [layer],
target: "map",
view: new ol.View({
// adjust zoom levels to those provided by the source
resolutions: layer.getSource().getTileGrid().getResolutions(),
// constrain the center: center cannot be set outside this extent
extent: extent,
constrainOnlyCenter: true,
}),
});

map.getView().fit(extent);
</script>
</body>
</html>
Binary file added docs/tiles/0/0-0.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docs/tiles/1/0-0.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docs/tiles/1/0-1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docs/tiles/1/1-0.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docs/tiles/1/1-1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docs/tiles/2/0-0.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docs/tiles/2/0-1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docs/tiles/2/0-2.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docs/tiles/2/0-3.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docs/tiles/2/1-0.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docs/tiles/2/1-1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docs/tiles/2/1-2.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docs/tiles/2/1-3.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docs/tiles/2/2-0.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docs/tiles/2/2-1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docs/tiles/2/2-2.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docs/tiles/2/2-3.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docs/tiles/2/3-0.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docs/tiles/2/3-1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docs/tiles/2/3-2.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docs/tiles/2/3-3.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docs/tiles/3/0-0.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docs/tiles/3/0-1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docs/tiles/3/0-2.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docs/tiles/3/0-3.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docs/tiles/3/0-4.png
Binary file added docs/tiles/3/0-5.png
Binary file added docs/tiles/3/0-6.png
Binary file added docs/tiles/3/0-7.png
Binary file added docs/tiles/3/1-0.png
Binary file added docs/tiles/3/1-1.png
Binary file added docs/tiles/3/1-2.png
Binary file added docs/tiles/3/1-3.png
Binary file added docs/tiles/3/1-4.png
Binary file added docs/tiles/3/1-5.png
Binary file added docs/tiles/3/1-6.png
Binary file added docs/tiles/3/1-7.png
Binary file added docs/tiles/3/2-0.png
Binary file added docs/tiles/3/2-1.png
Binary file added docs/tiles/3/2-2.png
Binary file added docs/tiles/3/2-3.png
Binary file added docs/tiles/3/2-4.png
Binary file added docs/tiles/3/2-5.png
Binary file added docs/tiles/3/2-6.png
Binary file added docs/tiles/3/2-7.png
Binary file added docs/tiles/3/3-0.png
Binary file added docs/tiles/3/3-1.png
Binary file added docs/tiles/3/3-2.png
Binary file added docs/tiles/3/3-3.png
Binary file added docs/tiles/3/3-4.png
Binary file added docs/tiles/3/3-5.png
Binary file added docs/tiles/3/3-6.png
Binary file added docs/tiles/3/3-7.png
Binary file added docs/tiles/3/4-0.png
Binary file added docs/tiles/3/4-1.png
Binary file added docs/tiles/3/4-2.png
Binary file added docs/tiles/3/4-3.png
Binary file added docs/tiles/3/4-4.png
Binary file added docs/tiles/3/4-5.png
Binary file added docs/tiles/3/4-6.png
Binary file added docs/tiles/3/4-7.png
Binary file added docs/tiles/3/5-0.png
Binary file added docs/tiles/3/5-1.png
Binary file added docs/tiles/3/5-2.png
Binary file added docs/tiles/3/5-3.png
Binary file added docs/tiles/3/5-4.png
Binary file added docs/tiles/3/5-5.png
Binary file added docs/tiles/3/5-6.png
Binary file added docs/tiles/3/5-7.png
Binary file added docs/tiles/3/6-0.png
Binary file added docs/tiles/3/6-1.png
Binary file added docs/tiles/3/6-2.png
Binary file added docs/tiles/3/6-3.png
Binary file added docs/tiles/3/6-4.png
Binary file added docs/tiles/3/6-5.png
Binary file added docs/tiles/3/6-6.png
Binary file added docs/tiles/3/6-7.png
Binary file added docs/tiles/3/7-0.png
Binary file added docs/tiles/3/7-1.png
Binary file added docs/tiles/3/7-2.png
Binary file added docs/tiles/3/7-3.png
Binary file added docs/tiles/3/7-4.png
Binary file added docs/tiles/3/7-5.png
Binary file added docs/tiles/3/7-6.png
Binary file added docs/tiles/3/7-7.png
Binary file added docs/tiles/4/0-0.png
Binary file added docs/tiles/4/0-1.png
Binary file added docs/tiles/4/0-10.png
Binary file added docs/tiles/4/0-11.png
Binary file added docs/tiles/4/0-12.png
Binary file added docs/tiles/4/0-13.png
Binary file added docs/tiles/4/0-14.png
Binary file added docs/tiles/4/0-15.png
Binary file added docs/tiles/4/0-2.png
Binary file added docs/tiles/4/0-3.png
Binary file added docs/tiles/4/0-4.png
Binary file added docs/tiles/4/0-5.png
Binary file added docs/tiles/4/0-6.png
Binary file added docs/tiles/4/0-7.png
Binary file added docs/tiles/4/0-8.png
Binary file added docs/tiles/4/0-9.png
Binary file added docs/tiles/4/1-0.png
Binary file added docs/tiles/4/1-1.png
Binary file added docs/tiles/4/1-10.png
Binary file added docs/tiles/4/1-11.png
Binary file added docs/tiles/4/1-12.png
Binary file added docs/tiles/4/1-13.png
Binary file added docs/tiles/4/1-14.png
Binary file added docs/tiles/4/1-15.png
Binary file added docs/tiles/4/1-2.png
Binary file added docs/tiles/4/1-3.png
Binary file added docs/tiles/4/1-4.png
Binary file added docs/tiles/4/1-5.png
Binary file added docs/tiles/4/1-6.png
Binary file added docs/tiles/4/1-7.png
Binary file added docs/tiles/4/1-8.png
Binary file added docs/tiles/4/1-9.png
Binary file added docs/tiles/4/10-0.png
Binary file added docs/tiles/4/10-1.png
Binary file added docs/tiles/4/10-10.png
Binary file added docs/tiles/4/10-11.png
Binary file added docs/tiles/4/10-12.png
Binary file added docs/tiles/4/10-13.png
Binary file added docs/tiles/4/10-14.png
Binary file added docs/tiles/4/10-15.png
Binary file added docs/tiles/4/10-2.png
Binary file added docs/tiles/4/10-3.png
Binary file added docs/tiles/4/10-4.png
Binary file added docs/tiles/4/10-5.png
Binary file added docs/tiles/4/10-6.png
Binary file added docs/tiles/4/10-7.png
Binary file added docs/tiles/4/10-8.png
Binary file added docs/tiles/4/10-9.png
Binary file added docs/tiles/4/11-0.png
Binary file added docs/tiles/4/11-1.png
Binary file added docs/tiles/4/11-10.png
Binary file added docs/tiles/4/11-11.png
Binary file added docs/tiles/4/11-12.png
Binary file added docs/tiles/4/11-13.png
Binary file added docs/tiles/4/11-14.png
Binary file added docs/tiles/4/11-15.png
Binary file added docs/tiles/4/11-2.png
Binary file added docs/tiles/4/11-3.png
Binary file added docs/tiles/4/11-4.png
Binary file added docs/tiles/4/11-5.png
Binary file added docs/tiles/4/11-6.png
Binary file added docs/tiles/4/11-7.png
Binary file added docs/tiles/4/11-8.png
Binary file added docs/tiles/4/11-9.png
Binary file added docs/tiles/4/12-0.png
Binary file added docs/tiles/4/12-1.png
Binary file added docs/tiles/4/12-10.png
Binary file added docs/tiles/4/12-11.png
Binary file added docs/tiles/4/12-12.png
Binary file added docs/tiles/4/12-13.png
Binary file added docs/tiles/4/12-14.png
Binary file added docs/tiles/4/12-15.png
Binary file added docs/tiles/4/12-2.png
Binary file added docs/tiles/4/12-3.png
Binary file added docs/tiles/4/12-4.png
Binary file added docs/tiles/4/12-5.png
Binary file added docs/tiles/4/12-6.png
Binary file added docs/tiles/4/12-7.png
Binary file added docs/tiles/4/12-8.png
Binary file added docs/tiles/4/12-9.png
Binary file added docs/tiles/4/13-0.png
Binary file added docs/tiles/4/13-1.png
Binary file added docs/tiles/4/13-10.png
Binary file added docs/tiles/4/13-11.png
Binary file added docs/tiles/4/13-12.png
Binary file added docs/tiles/4/13-13.png
Binary file added docs/tiles/4/13-14.png
Binary file added docs/tiles/4/13-15.png
Binary file added docs/tiles/4/13-2.png
Binary file added docs/tiles/4/13-3.png
Binary file added docs/tiles/4/13-4.png
Binary file added docs/tiles/4/13-5.png
Binary file added docs/tiles/4/13-6.png
Binary file added docs/tiles/4/13-7.png
Binary file added docs/tiles/4/13-8.png
Binary file added docs/tiles/4/13-9.png
Binary file added docs/tiles/4/14-0.png
Binary file added docs/tiles/4/14-1.png
Binary file added docs/tiles/4/14-10.png
Binary file added docs/tiles/4/14-11.png
Binary file added docs/tiles/4/14-12.png
Binary file added docs/tiles/4/14-13.png
Binary file added docs/tiles/4/14-14.png
Binary file added docs/tiles/4/14-15.png
Binary file added docs/tiles/4/14-2.png
Binary file added docs/tiles/4/14-3.png
Binary file added docs/tiles/4/14-4.png
Binary file added docs/tiles/4/14-5.png
Binary file added docs/tiles/4/14-6.png
Binary file added docs/tiles/4/14-7.png
Binary file added docs/tiles/4/14-8.png
Binary file added docs/tiles/4/14-9.png
Binary file added docs/tiles/4/15-0.png
Binary file added docs/tiles/4/15-1.png
Binary file added docs/tiles/4/15-10.png
Binary file added docs/tiles/4/15-11.png
Binary file added docs/tiles/4/15-12.png
Binary file added docs/tiles/4/15-13.png
Binary file added docs/tiles/4/15-14.png
Binary file added docs/tiles/4/15-15.png
Binary file added docs/tiles/4/15-2.png
Binary file added docs/tiles/4/15-3.png
Binary file added docs/tiles/4/15-4.png
Binary file added docs/tiles/4/15-5.png
Binary file added docs/tiles/4/15-6.png
Binary file added docs/tiles/4/15-7.png
Binary file added docs/tiles/4/15-8.png
Binary file added docs/tiles/4/15-9.png
Binary file added docs/tiles/4/2-0.png
Binary file added docs/tiles/4/2-1.png
Binary file added docs/tiles/4/2-10.png
Binary file added docs/tiles/4/2-11.png
Binary file added docs/tiles/4/2-12.png
Binary file added docs/tiles/4/2-13.png
Binary file added docs/tiles/4/2-14.png
Binary file added docs/tiles/4/2-15.png
Binary file added docs/tiles/4/2-2.png
Binary file added docs/tiles/4/2-3.png
Binary file added docs/tiles/4/2-4.png
Binary file added docs/tiles/4/2-5.png
Binary file added docs/tiles/4/2-6.png
Binary file added docs/tiles/4/2-7.png
Binary file added docs/tiles/4/2-8.png
Binary file added docs/tiles/4/2-9.png
Binary file added docs/tiles/4/3-0.png
Binary file added docs/tiles/4/3-1.png
Binary file added docs/tiles/4/3-10.png
Binary file added docs/tiles/4/3-11.png
Binary file added docs/tiles/4/3-12.png
Binary file added docs/tiles/4/3-13.png
Binary file added docs/tiles/4/3-14.png
Binary file added docs/tiles/4/3-15.png
Binary file added docs/tiles/4/3-2.png
Binary file added docs/tiles/4/3-3.png
Binary file added docs/tiles/4/3-4.png
Binary file added docs/tiles/4/3-5.png
Binary file added docs/tiles/4/3-6.png
Binary file added docs/tiles/4/3-7.png
Binary file added docs/tiles/4/3-8.png
Binary file added docs/tiles/4/3-9.png
Binary file added docs/tiles/4/4-0.png
Binary file added docs/tiles/4/4-1.png
Binary file added docs/tiles/4/4-10.png
Binary file added docs/tiles/4/4-11.png
Binary file added docs/tiles/4/4-12.png
Binary file added docs/tiles/4/4-13.png
Binary file added docs/tiles/4/4-14.png
Binary file added docs/tiles/4/4-15.png
Binary file added docs/tiles/4/4-2.png
Binary file added docs/tiles/4/4-3.png
Binary file added docs/tiles/4/4-4.png
Binary file added docs/tiles/4/4-5.png
Binary file added docs/tiles/4/4-6.png
Binary file added docs/tiles/4/4-7.png
Binary file added docs/tiles/4/4-8.png
Binary file added docs/tiles/4/4-9.png
Binary file added docs/tiles/4/5-0.png
Binary file added docs/tiles/4/5-1.png
Binary file added docs/tiles/4/5-10.png
Binary file added docs/tiles/4/5-11.png
Binary file added docs/tiles/4/5-12.png
Binary file added docs/tiles/4/5-13.png
Binary file added docs/tiles/4/5-14.png
Binary file added docs/tiles/4/5-15.png
Binary file added docs/tiles/4/5-2.png
Binary file added docs/tiles/4/5-3.png
Binary file added docs/tiles/4/5-4.png
Binary file added docs/tiles/4/5-5.png
Binary file added docs/tiles/4/5-6.png
Binary file added docs/tiles/4/5-7.png
Binary file added docs/tiles/4/5-8.png
Binary file added docs/tiles/4/5-9.png
Binary file added docs/tiles/4/6-0.png
Binary file added docs/tiles/4/6-1.png
Binary file added docs/tiles/4/6-10.png
Binary file added docs/tiles/4/6-11.png
Binary file added docs/tiles/4/6-12.png
Binary file added docs/tiles/4/6-13.png
Binary file added docs/tiles/4/6-14.png
Binary file added docs/tiles/4/6-15.png
Binary file added docs/tiles/4/6-2.png
Binary file added docs/tiles/4/6-3.png
Binary file added docs/tiles/4/6-4.png
Binary file added docs/tiles/4/6-5.png
Binary file added docs/tiles/4/6-6.png
Binary file added docs/tiles/4/6-7.png
Binary file added docs/tiles/4/6-8.png
Binary file added docs/tiles/4/6-9.png
Binary file added docs/tiles/4/7-0.png
Binary file added docs/tiles/4/7-1.png
Loading

0 comments on commit c129408

Please sign in to comment.