Created
July 15, 2017 01:33
-
-
Save sjenning/8b58cd1856d505bdec623abcea741433 to your computer and use it in GitHub Desktop.
UWP Asset Generator
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
package main | |
import ( | |
"fmt" | |
"gopkg.in/gographics/imagick.v2/imagick" | |
) | |
type asset struct { | |
size float32 | |
scales []float32 | |
} | |
func main() { | |
imagick.Initialize() | |
defer imagick.Terminate() | |
scales := []float32{1, 1.25, 1.5, 2, 4} | |
tileBaseSizes := []float32{44, 100, 150} | |
for _, baseSize := range tileBaseSizes { | |
for _, scale := range scales { | |
outfile := fmt.Sprintf("Square%dx%dLogo.scale-%d.png", uint(baseSize), uint(baseSize), uint(scale*100)) | |
size := round(baseSize * scale) | |
createAsset("tile.png", outfile, size, size) | |
} | |
} | |
for _, scale := range scales { | |
outfile := fmt.Sprintf("SmallTile.scale-%d.png", uint(scale*100)) | |
size := round(71 * scale) | |
createAsset("tile.png", outfile, size, size) | |
} | |
targetSizes := []uint{16, 24, 32, 48, 256} | |
for _, size := range targetSizes { | |
outfile := fmt.Sprintf("Square44x44Logo.targetsize-%d.png", size) | |
createAsset("tile.png", outfile, size, size) | |
} | |
for _, size := range targetSizes { | |
outfile := fmt.Sprintf("Square44x44Logo.altform-unplated_targetsize-%d.png", size) | |
createAsset("unplated.png", outfile, size, size) | |
} | |
for _, scale := range scales { | |
size := uint(310.0 * scale) | |
outfile := fmt.Sprintf("LargeTile.scale-%d.png", uint(scale*100)) | |
createAsset("large.png", outfile, size, size) | |
} | |
for _, scale := range scales { | |
width := round(310.0 * scale) | |
height := round(150.0 * scale) | |
outfile := fmt.Sprintf("Wide%dx%dLogo.scale-%d.png", 310, 150, uint(scale*100)) | |
createAsset("wide.png", outfile, width, height) | |
} | |
} | |
func round(f float32) uint { | |
return uint(f + 0.5) | |
} | |
func createAsset(infile, outfile string, width, height uint) { | |
mw := imagick.NewMagickWand() | |
err := mw.ReadImage(infile) | |
if err != nil { | |
panic(err) | |
} | |
err = mw.ResizeImage(width, height, imagick.FILTER_LANCZOS, 1) | |
if err != nil { | |
panic(err) | |
} | |
fmt.Println("Generating", outfile) | |
err = mw.WriteImage(outfile) | |
if err != nil { | |
panic(err) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment