Handle zoom levels
This commit is contained in:
parent
286f0fca0b
commit
76afabb1d8
@ -1 +1,9 @@
|
|||||||
# slicerdicer
|
# slicerdicer
|
||||||
|
|
||||||
|
Slice and dice an image, turning it into many equal sized tiles.
|
||||||
|
|
||||||
|
## Usage
|
||||||
|
|
||||||
|
slicerdicer -help
|
||||||
|
|
||||||
|
slicerdicer --filename foo.png --tile-size 256
|
||||||
|
24
main.go
24
main.go
@ -31,11 +31,30 @@ func main() {
|
|||||||
|
|
||||||
fmt.Println("starting tiling")
|
fmt.Println("starting tiling")
|
||||||
|
|
||||||
|
z := 0
|
||||||
|
|
||||||
|
// outer loop for zoom
|
||||||
|
for {
|
||||||
|
if (z == 0) {
|
||||||
|
// do nothing
|
||||||
|
} else {
|
||||||
|
// halve image size
|
||||||
|
src = imaging.Resize(src, size.X/2, 0, imaging.Linear)
|
||||||
|
// recalculate size
|
||||||
|
size = src.Bounds().Max
|
||||||
|
// we are done if we are now smaller then the tile
|
||||||
|
if (size.X < tile_size_x || size.Y < tile_size_y) {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fmt.Print(fmt.Sprintf("zoom level: %d (%d x %d)\n", z, size.X, size.Y))
|
||||||
|
|
||||||
for y := 0 ; y <= (size.Y / tile_size_y) ; y++ {
|
for y := 0 ; y <= (size.Y / tile_size_y) ; y++ {
|
||||||
|
|
||||||
for x := 0 ; x <= (size.X / tile_size_x) ; x++ {
|
for x := 0 ; x <= (size.X / tile_size_x) ; x++ {
|
||||||
|
|
||||||
output_filename := fmt.Sprintf("tile-0-%d-%d.png", x, y)
|
output_filename := fmt.Sprintf("tile-%d-%d-%d.png", z, x, y)
|
||||||
cropped := imaging.Crop(src, image.Rect(tile_size_x*x, tile_size_y*y, tile_size_x*x+tile_size_x, tile_size_y*y+tile_size_y));
|
cropped := imaging.Crop(src, image.Rect(tile_size_x*x, tile_size_y*y, tile_size_x*x+tile_size_x, tile_size_y*y+tile_size_y));
|
||||||
|
|
||||||
fmt.Print("writing to: ", output_filename, " ");
|
fmt.Print("writing to: ", output_filename, " ");
|
||||||
@ -52,6 +71,9 @@ func main() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fmt.Println()
|
fmt.Println()
|
||||||
|
z++
|
||||||
|
}
|
||||||
|
|
||||||
fmt.Println("done")
|
fmt.Println("done")
|
||||||
|
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user