Compare commits
2
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
9116b93d67 | ||
|
|
5c5794916a |
+61
-69
@@ -15,7 +15,6 @@ import (
|
|||||||
|
|
||||||
"github.com/gen2brain/avif"
|
"github.com/gen2brain/avif"
|
||||||
"golang.org/x/image/draw"
|
"golang.org/x/image/draw"
|
||||||
"golang.org/x/sync/errgroup"
|
|
||||||
"zombiezen.com/go/sqlite"
|
"zombiezen.com/go/sqlite"
|
||||||
"zombiezen.com/go/sqlite/sqlitex"
|
"zombiezen.com/go/sqlite/sqlitex"
|
||||||
)
|
)
|
||||||
@@ -38,16 +37,16 @@ func saveImgs(ctx context.Context, db *sqlitex.Pool, out string) {
|
|||||||
slog.Error("supports", slog.Any("err", err))
|
slog.Error("supports", slog.Any("err", err))
|
||||||
}
|
}
|
||||||
|
|
||||||
g, ctx := errgroup.WithContext(ctx)
|
|
||||||
g.SetLimit(2)
|
|
||||||
tick := time.NewTicker(250 * time.Millisecond)
|
tick := time.NewTicker(250 * time.Millisecond)
|
||||||
idouts(ctx, g, tick, skill, filepath.Join(out, "skill"), "https://media.gametora.com/umamusume/skills/icon/%d.png", image.Pt(64, 64), image.Pt(32, 32), image.Pt(16, 16))
|
err = errors.Join(
|
||||||
idouts(ctx, g, tick, chara, filepath.Join(out, "chara"), "https://gametora.com/images/umamusume/characters/icons/chr_icon_%d.png", image.Pt(256, 256), image.Pt(64, 64), image.Pt(32, 32), image.Pt(16, 16))
|
idouts(ctx, tick, skill, filepath.Join(out, "skill"), "https://media.gametora.com/umamusume/skills/icon/%d.png", image.Pt(64, 64), image.Pt(32, 32), image.Pt(16, 16)),
|
||||||
idouts(ctx, g, tick, rank, filepath.Join(out, "rank"), "https://media.gametora.com/umamusume/ui/rank/%02d.png", image.Pt(128, 128), image.Pt(64, 64), image.Pt(32, 32), image.Pt(16, 16))
|
idouts(ctx, tick, chara, filepath.Join(out, "chara"), "https://gametora.com/images/umamusume/characters/icons/chr_icon_%d.png", image.Pt(256, 256), image.Pt(64, 64), image.Pt(32, 32), image.Pt(16, 16)),
|
||||||
idouts(ctx, g, tick, rank, filepath.Join(out, "rank", "simple"), "https://media.gametora.com/umamusume/ui/rank/simple/%02d.png", image.Pt(50, 50), image.Pt(32, 32), image.Pt(16, 16))
|
idouts(ctx, tick, rank, filepath.Join(out, "rank"), "https://media.gametora.com/umamusume/ui/rank/%02d.png", image.Pt(128, 128), image.Pt(64, 64), image.Pt(32, 32), image.Pt(16, 16)),
|
||||||
idouts(ctx, g, tick, supps, filepath.Join(out, "support"), "https://gametora.com/images/umamusume/supports/support_card_s_%d.png", image.Pt(128, 128), image.Pt(64, 64), image.Pt(32, 32))
|
idouts(ctx, tick, rank, filepath.Join(out, "rank", "simple"), "https://media.gametora.com/umamusume/ui/rank/simple/%02d.png", image.Pt(50, 50), image.Pt(32, 32), image.Pt(16, 16)),
|
||||||
idouts(ctx, g, tick, []int32{0, 1, 2, 3, 4, 5, 6}, filepath.Join(out, "support", "type"), "https://gametora.com/images/umamusume/icons/utx_ico_obtain_%02d.png", image.Pt(70, 70), image.Pt(35, 35), image.Pt(16, 16))
|
idouts(ctx, tick, supps, filepath.Join(out, "support"), "https://gametora.com/images/umamusume/supports/support_card_s_%d.png", image.Pt(128, 128), image.Pt(64, 64), image.Pt(32, 32)),
|
||||||
if err := g.Wait(); err != nil {
|
idouts(ctx, tick, []int32{0, 1, 2, 3, 4, 5, 6}, filepath.Join(out, "support", "type"), "https://gametora.com/images/umamusume/icons/utx_ico_obtain_%02d.png", image.Pt(70, 70), image.Pt(35, 35), image.Pt(16, 16)),
|
||||||
|
)
|
||||||
|
if err != nil {
|
||||||
slog.Error("output", slog.Any("err", err))
|
slog.Error("output", slog.Any("err", err))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -103,58 +102,61 @@ func suppIDs(ctx context.Context, db *sqlitex.Pool) ([]int32, error) {
|
|||||||
|
|
||||||
var pngenc = &png.Encoder{CompressionLevel: png.BestCompression}
|
var pngenc = &png.Encoder{CompressionLevel: png.BestCompression}
|
||||||
|
|
||||||
func idouts(ctx context.Context, g *errgroup.Group, tick *time.Ticker, ids []int32, p, urlf string, sizes ...image.Point) {
|
func idouts(ctx context.Context, tick *time.Ticker, ids []int32, p, urlf string, sizes ...image.Point) error {
|
||||||
for _, id := range ids {
|
for _, id := range ids {
|
||||||
g.Go(func() error {
|
n := strconv.Itoa(int(id))
|
||||||
n := strconv.Itoa(int(id))
|
p := filepath.Join(p, n)
|
||||||
p := filepath.Join(p, n)
|
_, err := os.Stat(p)
|
||||||
_, err := os.Stat(p)
|
if !errors.Is(err, os.ErrNotExist) {
|
||||||
if !errors.Is(err, os.ErrNotExist) {
|
slog.DebugContext(ctx, "exists", slog.String("path", p))
|
||||||
slog.DebugContext(ctx, "exists", slog.String("path", p))
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
if err := os.MkdirAll(p, 0777); err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
url := fmt.Sprintf(urlf, id)
|
|
||||||
select {
|
|
||||||
case <-ctx.Done():
|
|
||||||
return ctx.Err()
|
|
||||||
case <-tick.C: // continue on
|
|
||||||
}
|
|
||||||
img, err := dlimg(ctx, url)
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
slog.InfoContext(ctx, "resize", slog.String("url", url))
|
|
||||||
rs := resize(img, sizes...)
|
|
||||||
for _, r := range rs {
|
|
||||||
g.Go(func() error {
|
|
||||||
m := r.Bounds().Max
|
|
||||||
o := filepath.Join(p, fmt.Sprintf("%dx%d.png", m.X, m.Y))
|
|
||||||
slog.InfoContext(ctx, "write", slog.String("path", o))
|
|
||||||
f, err := os.Create(o)
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
defer f.Close()
|
|
||||||
return pngenc.Encode(f, r)
|
|
||||||
})
|
|
||||||
g.Go(func() error {
|
|
||||||
m := r.Bounds().Max
|
|
||||||
o := filepath.Join(p, fmt.Sprintf("%dx%d.avif", m.X, m.Y))
|
|
||||||
slog.InfoContext(ctx, "write", slog.String("path", o))
|
|
||||||
f, err := os.Create(o)
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
defer f.Close()
|
|
||||||
return avif.Encode(f, r)
|
|
||||||
})
|
|
||||||
}
|
|
||||||
return nil
|
return nil
|
||||||
})
|
}
|
||||||
|
if err := os.MkdirAll(p, 0777); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
url := fmt.Sprintf(urlf, id)
|
||||||
|
select {
|
||||||
|
case <-ctx.Done():
|
||||||
|
return ctx.Err()
|
||||||
|
case <-tick.C: // continue on
|
||||||
|
}
|
||||||
|
img, err := dlimg(ctx, url)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
slog.InfoContext(ctx, "resize", slog.String("url", url))
|
||||||
|
for _, sz := range sizes {
|
||||||
|
r := image.NewNRGBA(image.Rectangle{Min: image.Point{}, Max: sz})
|
||||||
|
draw.CatmullRom.Scale(r, r.Bounds(), img, img.Bounds(), draw.Src, nil)
|
||||||
|
{
|
||||||
|
m := r.Bounds().Max
|
||||||
|
o := filepath.Join(p, fmt.Sprintf("%dx%d.png", m.X, m.Y))
|
||||||
|
slog.InfoContext(ctx, "write", slog.String("path", o))
|
||||||
|
f, err := os.Create(o)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
defer f.Close()
|
||||||
|
if err := pngenc.Encode(f, r); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
}
|
||||||
|
{
|
||||||
|
m := r.Bounds().Max
|
||||||
|
o := filepath.Join(p, fmt.Sprintf("%dx%d.avif", m.X, m.Y))
|
||||||
|
slog.InfoContext(ctx, "write", slog.String("path", o))
|
||||||
|
f, err := os.Create(o)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
defer f.Close()
|
||||||
|
if err := avif.Encode(f, r); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func dlimg(ctx context.Context, url string) (image.Image, error) {
|
func dlimg(ctx context.Context, url string) (image.Image, error) {
|
||||||
@@ -174,13 +176,3 @@ func dlimg(ctx context.Context, url string) (image.Image, error) {
|
|||||||
img, _, err := image.Decode(resp.Body)
|
img, _, err := image.Decode(resp.Body)
|
||||||
return img, err
|
return img, err
|
||||||
}
|
}
|
||||||
|
|
||||||
func resize(img image.Image, sizes ...image.Point) []image.Image {
|
|
||||||
rs := make([]image.Image, 0, len(sizes))
|
|
||||||
for _, sz := range sizes {
|
|
||||||
d := image.NewNRGBA(image.Rectangle{Min: image.Point{}, Max: sz})
|
|
||||||
draw.CatmullRom.Scale(d, d.Bounds(), img, img.Bounds(), draw.Src, nil)
|
|
||||||
rs = append(rs, d)
|
|
||||||
}
|
|
||||||
return rs
|
|
||||||
}
|
|
||||||
|
|||||||
Reference in New Issue
Block a user