Automattic / Automattic/node-canvas

Incorrect transparent GIF blending when it's transparent color is not black

Open
#116 3 comments 0 reactions 0 assignees View on GitHub
Bug Help wanted Images & Formats: GIF
Dominant language
JavaScript
Stars
10.7k
Forks
1.2k
Avg merge
4d 8h
Merged PRs (30d)
1

Description

The value of the color marked as transparent is not discarded, but blended with background using "add" operation if the background isn't transparent.

For example, here is an image that is transparent, but the color of the transparent index in it's palette is set to `#804000`:
![transparent gif](https://i.imgur.com/XCz0eVi.gif)

``` javascript
var assert = require('assert')
var Canvas = require('canvas')

var c = new Canvas(150, 150)
var ctx = c.getContext('2d')

// fill background with something non-transparent
ctx.fillStyle = 'rgb(0, 100, 200)'
ctx.fillRect(0, 0, 150, 150)
// load the (supposedly) transparent gif
var i = new Canvas.Image()
i.src = 'transparent.gif' // https://i.imgur.com/XCz0eVi.gif
// draw it on top of our background
ctx.drawImage(i, 0, 0)
// expect no visible change in the canvas
var pixel = ctx.getImageData(0, 0, 1, 1).data
assert.deepEqual(pixel, [0, 100, 200, 255])
```

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.