Files
navi/tools/mk300/main.go
T
NavisandCursor 50f7f71393 Add site contacts/FAQ and accept AWG 2.0 / naive pastes in Add config.
ImportSubscription no longer requires only http(s): paste awg://, AWG .conf/JSON, or naive links; subscription parser also reads hosted AWG and Clash wireguard/naive. Site lists support emails and FAQ; Store listing texts/tools updated.

Co-authored-by: Cursor <cursoragent@cursor.com>
2026-08-02 15:40:13 +03:00

83 lines
2.2 KiB
Go

package main
import (
"fmt"
"image"
"image/color"
"image/draw"
"image/png"
"os"
"path/filepath"
xdraw "golang.org/x/image/draw"
)
func writePNG(path string, img image.Image) {
_ = os.MkdirAll(filepath.Dir(path), 0755)
out, err := os.Create(path)
if err != nil {
panic(err)
}
defer out.Close()
enc := png.Encoder{CompressionLevel: png.BestCompression}
if err := enc.Encode(out, img); err != nil {
panic(err)
}
fmt.Println("wrote", path)
}
func main() {
root := `D:\vpn navi`
srcPath := filepath.Join(root, "screen", "1.ru.png")
f, err := os.Open(srcPath)
if err != nil {
panic(err)
}
src, err := png.Decode(f)
f.Close()
if err != nil {
panic(err)
}
sb := src.Bounds()
sw, sh := sb.Dx(), sb.Dy()
side := sw
if sh < side {
side = sh
}
// Center crop to square — no stretch/distortion.
ox := sb.Min.X + (sw-side)/2
oy := sb.Min.Y + (sh-side)/2
crop := image.NewRGBA(image.Rect(0, 0, side, side))
draw.Draw(crop, crop.Bounds(), src, image.Pt(ox, oy), draw.Src)
dst := image.NewRGBA(image.Rect(0, 0, 300, 300))
xdraw.CatmullRom.Scale(dst, dst.Bounds(), crop, crop.Bounds(), xdraw.Over, nil)
writePNG(filepath.Join(root, "screen", "1.ru.300x300.png"), dst)
writePNG(filepath.Join(root, "dist", "microsoft-store", "listing", "screen", "1.ru.300x300.png"), dst)
writePNG(filepath.Join(root, "packaging", "msix", "Assets", "StoreLogo300x300.png"), dst)
// Padded fit (full frame, letterbox) — no crop.
fit := image.NewRGBA(image.Rect(0, 0, 300, 300))
draw.Draw(fit, fit.Bounds(), &image.Uniform{C: color.White}, image.Point{}, draw.Src)
scale := float64(300) / float64(sw)
if float64(sh)*scale > 300 {
scale = float64(300) / float64(sh)
}
nw := int(float64(sw) * scale)
nh := int(float64(sh) * scale)
if nw < 1 {
nw = 1
}
if nh < 1 {
nh = 1
}
resized := image.NewRGBA(image.Rect(0, 0, nw, nh))
xdraw.CatmullRom.Scale(resized, resized.Bounds(), src, sb, xdraw.Over, nil)
off := image.Pt((300-nw)/2, (300-nh)/2)
draw.Draw(fit, image.Rect(off.X, off.Y, off.X+nw, off.Y+nh), resized, image.Point{}, draw.Over)
writePNG(filepath.Join(root, "screen", "1.ru.300x300.fit.png"), fit)
fmt.Printf("source %dx%d -> crop %dx%d -> 300x300 (CatmullRom)\n", sw, sh, side, side)
}