Automattic/node-canvas

Wrong Image ColorSpace in PDF for JPEG with ICC

Offen

#1.621 geöffnet am 16.07.2020

 (0 Kommentare) (0 Reaktionen) (0 zugewiesene Personen)JavaScript (1.195 Forks)batch import
BugHelp wantedImages & Formats: JPEG

Repository-Metriken

Stars
 (10.689 Sterne)
PR-Merge-Metriken
 (PR-Metriken ausstehend)

Beschreibung

Issue

If you create a PDF file, JPEG images with ICC profile are saved in the wrong color space.

Steps to Reproduce

With a JPEG image with an embedded ICC profile:

const fs = require('fs')
const { Image, createCanvas } = require('canvas')

const canvas = createCanvas(100, 100, 'pdf')

const image = new Image()
image.dataMode = Image.MODE_MIME | Image.MODE_IMAGE

image.onload = () => {
    canvas.width = image.width
    canvas.height = image.height
    const ctx = canvas.getContext('2d')
    ctx.drawImage(image, 0, 0, image.width, image.height)
    fs.writeFileSync('out.pdf', canvas.toBuffer())
}

image.src = 'image-with-icc-profile.jpg'

This embeds the JPEG image (with embedded ICC profile) unchanged in the PDF and sets its color space to DeviceRGB. This means that the ICC profile is not applied to the image.

The correct behavior would be to save the ICC profile as a further stream in the PDF and to reference it as ICCBased color space.

Environment

  • node-canvas 2.6.1
  • node 12.18.2 on Ubuntu 18.04.4

Contributor Guide