noita-mapcap/bin/stitch/export-dzi.go

39 lines
990 B
Go
Raw Permalink Normal View History

// Copyright (c) 2023 David Vogel
//
// This software is released under the MIT License.
// https://opensource.org/licenses/MIT
package main
import (
"fmt"
"os"
"path/filepath"
"strings"
)
2023-12-31 16:44:07 +00:00
func exportDZI(stitchedImage *StitchedImage, outputPath string, dziTileSize, dziOverlap int) error {
descriptorPath := outputPath
extension := filepath.Ext(outputPath)
outputTilesPath := strings.TrimSuffix(outputPath, extension) + "_files"
2023-12-31 16:44:07 +00:00
dzi := NewDZI(stitchedImage, dziTileSize, dziOverlap)
// Create base directory of all DZI files.
if err := os.MkdirAll(outputTilesPath, 0755); err != nil {
return fmt.Errorf("failed to create output directory: %w", err)
}
// Export DZI descriptor.
if err := dzi.ExportDZIDescriptor(descriptorPath); err != nil {
return fmt.Errorf("failed to export DZI descriptor: %w", err)
}
// Export DZI tiles.
if err := dzi.ExportDZITiles(outputTilesPath); err != nil {
return fmt.Errorf("failed to export DZI tiles: %w", err)
}
return nil
}