Skip to content

4 channel LZW TIFF output returns a value of 3 for info.channels #2064

@BryceCicada

Description

@BryceCicada
  System:
    OS: Linux 4.15 Ubuntu 18.04.1 LTS (Bionic Beaver)
    CPU: (8) x64 Intel(R) Xeon(R) CPU E3-1505M v6 @ 3.00GHz
    Memory: 1.68 GB / 15.52 GB
    Container: Yes
    Shell: 4.4.19 - /bin/bash
  Binaries:
    Node: 12.10.0 - /usr/bin/node
    npm: 6.12.0 - /usr/bin/npm
  Utilities:
    CMake: 3.10.2 - /usr/bin/cmake
    Make: 4.1 - /usr/bin/make
    GCC: 7.4.0 - /usr/bin/gcc
    Git: 2.17.1 - /usr/bin/git
    Subversion: 1.9.7 - /usr/bin/svn
    FFmpeg: 3.4.6 - /usr/bin/ffmpeg
  Languages:
    Bash: 4.4.19 - /bin/bash
    Go: 1.10.4 - /usr/bin/go
    Perl: 5.26.1 - /usr/bin/perl
    Python: 2.7.15+ - /usr/bin/python
    Python3: 3.6.8 - /usr/bin/python3
    Ruby: 2.5.1 - /usr/bin/ruby

I'm trying to create a 4-channel tiff from raw pixel data. Unfortunately, when this is written to disk, the image has only 3 channels. Here's snippet using sharp 0.24.0

import * as sharp from 'sharp'

async function main () {
  const width = 32
  const height = 32
  const channels = 4
  const info = await sharp(
    Buffer.from(new Array(width * height * channels).fill(0)),
    {
      raw: { width, height, channels }
    }
  ).toFile('test.tif')

  if (info.channels !== channels) {
    throw new Error(`Unexpected number of channels in output image. Expected ${channels}, but got ${info.channels}`)
  }
}

main()

Issue also occurs when saving jpgs (eg toFile('test.jpg')). Does not occur saving pngs.

I can't see anything obvious in the docs that excludes this possibility. Advice appreciated.

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions