• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

cshum / imagor / 15327609584

29 May 2025 03:37PM UTC coverage: 92.02%. Remained the same
15327609584

push

github

cshum
prepare FallbackFunc

0 of 6 new or added lines in 1 file covered. (0.0%)

4855 of 5276 relevant lines covered (92.02%)

1.1 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

15.15
/processor/vipsprocessor/fallback.go
1
package vipsprocessor
2

3
import (
4
        "github.com/cshum/imagor"
5
        "github.com/cshum/vipsgen/vips"
6
        "golang.org/x/image/bmp"
7
        "image"
8
        "image/draw"
9
        "io"
10
)
11

12
// FallbackFunc vips.Image fallback handler when vips.NewImageFromSource failed
13
type FallbackFunc func(blob *imagor.Blob, options *vips.LoadOptions) (*vips.Image, error)
14

15
// BufferFallbackFunc load image from buffer FallbackFunc
NEW
16
func BufferFallbackFunc(blob *imagor.Blob, options *vips.LoadOptions) (*vips.Image, error) {
×
NEW
17
        buf, err := blob.ReadAll()
×
NEW
18
        if err != nil {
×
NEW
19
                return nil, err
×
NEW
20
        }
×
NEW
21
        return vips.NewImageFromBuffer(buf, options)
×
22
}
23

24
func loadImageFromBMP(r io.Reader) (*vips.Image, error) {
×
25
        img, err := bmp.Decode(r)
×
26
        if err != nil {
×
27
                return nil, err
×
28
        }
×
29
        rect := img.Bounds()
×
30
        size := rect.Size()
×
31
        rgba, ok := img.(*image.RGBA)
×
32
        if !ok {
×
33
                rgba = image.NewRGBA(rect)
×
34
                draw.Draw(rgba, rect, img, rect.Min, draw.Src)
×
35
        }
×
36
        return vips.NewImageFromMemory(rgba.Pix, size.X, size.Y, 4)
×
37
}
38

39
func BmpFallbackFunc(blob *imagor.Blob, _ *vips.LoadOptions) (*vips.Image, error) {
1✔
40
        if blob.BlobType() == imagor.BlobTypeBMP {
1✔
41
                // fallback with Go BMP decoder if vips error on BMP
×
42
                r, _, err := blob.NewReader()
×
43
                if err != nil {
×
44
                        return nil, err
×
45
                }
×
46
                defer func() {
×
47
                        _ = r.Close()
×
48
                }()
×
49
                return loadImageFromBMP(r)
×
50
        } else {
1✔
51
                return nil, imagor.ErrUnsupportedFormat
1✔
52
        }
1✔
53
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc