-
-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
50 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -54,6 +54,7 @@ | |
"upscaled", | ||
"Vogel", | ||
"Voronoi", | ||
"webp", | ||
"xmax", | ||
"xmin", | ||
"ymax", | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
// Copyright (c) 2024 David Vogel | ||
// | ||
// This software is released under the MIT License. | ||
// https://opensource.org/licenses/MIT | ||
|
||
package main | ||
|
||
import ( | ||
"fmt" | ||
"image" | ||
"log" | ||
"os" | ||
|
||
"github.com/chai2010/webp" | ||
) | ||
|
||
func exportWebP(stitchedImage image.Image, outputPath string) error { | ||
log.Printf("Creating output file %q.", outputPath) | ||
|
||
return exportWebPSilent(stitchedImage, outputPath) | ||
} | ||
|
||
func exportWebPSilent(stitchedImage image.Image, outputPath string) error { | ||
bounds := stitchedImage.Bounds() | ||
if bounds.Dx() > 16383 || bounds.Dy() > 16383 { | ||
return fmt.Errorf("image size exceeds the maximum allowed size (16383) of a WebP image: %d x %d", bounds.Dx(), bounds.Dy()) | ||
} | ||
|
||
f, err := os.Create(outputPath) | ||
if err != nil { | ||
return fmt.Errorf("failed to create file: %w", err) | ||
} | ||
defer f.Close() | ||
|
||
if err = webp.Encode(f, stitchedImage, &webp.Options{Lossless: true}); err != nil { | ||
return fmt.Errorf("failed to encode image %q: %w", outputPath, err) | ||
} | ||
|
||
return nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters