Skip to content

Commit

Permalink
Use type switch to properly handle RGBA images from Decap
Browse files Browse the repository at this point in the history
Since updating Chrome/chromedp, the images from Decap are no longer
NRGBA. Apparently, the previous code for handling RGBA ended up
overwriting the image content when asserting type (i.e. `im` became
a nil pointer).
  • Loading branch information
glupmjoed committed Jun 6, 2024
1 parent 934ac6b commit 99b1fcf
Showing 1 changed file with 5 additions and 4 deletions.
9 changes: 5 additions & 4 deletions image.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,15 +54,16 @@ func (entry *CacheEntry) fetchAndCropImage(background, nocrop bool) error {
return err
}

var ok bool
var m *image.NRGBA
if im, ok = im.(*image.NRGBA); ok {
switch im.(type) {
case *image.NRGBA:
m = im.(*image.NRGBA)
} else {
fmt.Fprintf(os.Stderr, "Unexpected image type %T\n", im)
case *image.RGBA:
b := im.Bounds()
m = image.NewNRGBA(image.Rect(0, 0, b.Dx(), b.Dy()))
draw.Draw(m, m.Bounds(), im, b.Min, draw.Src)
default:
return fmt.Errorf("Unexpected image type %T", im)
}

if !nocrop {
Expand Down

0 comments on commit 99b1fcf

Please sign in to comment.