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) }