MCPcopy Create free account
hub / github.com/imgproxy/imgproxy / fixGifSize

Function fixGifSize

processing/fix_size.go:60–82  ·  view source on GitHub ↗
(img *vips.Image)

Source from the content-addressed store, hash-verified

58}
59
60func fixGifSize(img *vips.Image) error {
61 gifMaxResolution := float64(vips.GifResolutionLimit())
62 gifResLimitShrink := float64(img.Width()*img.Height()) / gifMaxResolution
63 gifDimLimitShrink := float64(max(img.Width(), img.Height())) / gifMaxDimension
64
65 gifLimitShrink := math.Max(gifResLimitShrink, gifDimLimitShrink)
66
67 if gifLimitShrink <= 1.0 {
68 return nil
69 }
70
71 scale := math.Sqrt(1.0 / gifLimitShrink)
72 if err := img.Resize(scale, scale); err != nil {
73 return err
74 }
75
76 slog.Warn(fmt.Sprintf(
77 "GIF resolution is limited to %d and dimension size is limited to %d. The image is rescaled to %dx%d",
78 int(gifMaxResolution), int(gifMaxDimension), img.Width(), img.Height(),
79 ))
80
81 return nil
82}
83
84func fixIcoSize(img *vips.Image) error {
85 icoLimitShrink := float64(max(img.Width(), img.Height())) / icoMaxDimension

Callers 1

fixSizeMethod · 0.85

Calls 5

GifResolutionLimitFunction · 0.92
ResizeMethod · 0.80
WarnMethod · 0.80
WidthMethod · 0.45
HeightMethod · 0.45

Tested by

no test coverage detected