sharp icon indicating copy to clipboard operation
sharp copied to clipboard

Image procesing in the CMYK colorspace

Open cagseylan opened this issue 2 years ago • 0 comments

Dear All, I have two questions about existing(?) features. I have a number of 5 channel images. The first 4 channels correspond to C, M, Y, and K in CMYK colorspace, the last channel is the alpha (transparency) channel. According to the API documentation I can create such an image by joining channels with raw data, and then converting the output to cmyk, the last channel being interpreted as alpha. However, when I query the metadata of the resulting image, it seems there are only 4 channels. Here is the code piece of this try:

const cmykImg = sharp(cBuf, {
        raw: {
            width: h,
            height: w,
            channels: 1
        }
    }).joinChannel(mBuf, {raw: {height: h, width: w, channels: 1}})
        .joinChannel(yBuf, {raw: {height: h, width: w, channels: 1}})
        .joinChannel(kBuf, {raw: {height: h, width: w, channels: 1}})
        .joinChannel(aBuf, {raw: {height: h, width: w, channels: 1}})
        .toColorspace('cmyk')

const cmykBuf = await cmykImg.tiff().toBuffer()
const imgTif = sharp(buf)

metadata() for imgTif is as follows:

{
  format: 'tiff',
  size: 4613,
  space: 'cmyk',
  channels: 4,
  depth: 'uchar',
  isProgressive: false,
  pages: 1,
  resolutionUnit: 'inch',
  hasProfile: false,
  hasAlpha: false,
  orientation: 1
}

I tried with tiff because it supports both cmyk and transparency. Although the colorspace is cmyk, number of channels is 4 and hasAlpha is false. Does sharp support such images currently? If yes, what is the correct way of achieving this?

Furthermore, I need to do image composition with these 5 channel images. I can do this with png images in sharp easily. Is composition supported in the same way with cmyk-alpha images?

cagseylan avatar Sep 06 '23 09:09 cagseylan