You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Combining a premultiplied CMYK TIFF file with an alpha channel while preserving its ICC profile.
What are you trying to achieve?
First of all, thank you for the great work on this library.
I'm trying to join an alpha channel to an existing CMYK tiff image while retaining the exact CMYK values and the original ICC profile. These are the files I received:
The only way I've succeeded is to re-encode using the source profile explicitly:
constalphaData=awaitsharp('rgba.png').extractChannel('alpha').png().toBuffer();awaitsharp('cmyk.tiff').joinChannel(alphaData).withIccProfile('source-profile.icc').tiff({compression: 'lzw'}).toFile('output.tiff');console.log((awaitsharp('output.tiff').metadata()));// CMYK space with 5 bands and ICC attached
This has some drawbacks though:
it requires extracting the ICC profile from the source file first
it re-encodes the file with the same profile, which feels unnecessary as CMYK values can be used as-is
the resulting file still needs to be unpremultiplied as the source TIFF file is premultiplied
For drawback (3), I found a workaround using libvips CLI directly:
The result output-unpremultiplied.tiff is exactly what I need. Unfortunately, since pipes can't stream these operations in the CLI (libvips/libvips#4256 (comment)), this approach generates intermediate files exceeding 160MB. Chaining operations using a library seems the recommended approach here.
My questions:
Is there a clean way to joinChannel an alpha channel while preserving the ICC profile without having to re-encode using withIccProfile?
What's the feasibility of providing a unpremultiply operation in sharp? (I've written a PR here previously, so I'd be happy to look into this if it's a welcome addition, but I suspect this might be challenging). Alternatively, would resolving sharp() constructor for raw pixel input has no colorspace parameter — blocks CMYK raw roundtrip #4521 be the better approach to handle this entirely with sharp? If I understand correctly, it would let me flag the raw image data as already premultiplied, though I'm unsure if that would prevent me from needing to unpremultiply after merging the alpha channel.
Question about an existing feature
Combining a premultiplied CMYK TIFF file with an alpha channel while preserving its ICC profile.
What are you trying to achieve?
First of all, thank you for the great work on this library.
I'm trying to join an alpha channel to an existing CMYK tiff image while retaining the exact CMYK values and the original ICC profile. These are the files I received:
cmyk.tiff: 4 bands + ICC profilergba.png: 3 bands + alpha channel.I'm trying to add the alpha channel from the PNG to the TIFF file, keeping the CMYK values exactly as-is.
I attempted to use
joinChanneland keep the profile, but I ran into a few different hurdles:The only way I've succeeded is to re-encode using the source profile explicitly:
This has some drawbacks though:
For drawback (3), I found a workaround using
libvipsCLI directly:The result
output-unpremultiplied.tiffis exactly what I need. Unfortunately, since pipes can't stream these operations in the CLI (libvips/libvips#4256 (comment)), this approach generates intermediate files exceeding 160MB. Chaining operations using a library seems the recommended approach here.My questions:
joinChannelan alpha channel while preserving the ICC profile without having to re-encode usingwithIccProfile?unpremultiplyoperation insharp? (I've written a PR here previously, so I'd be happy to look into this if it's a welcome addition, but I suspect this might be challenging). Alternatively, would resolving sharp() constructor for raw pixel input has no colorspace parameter — blocks CMYK raw roundtrip #4521 be the better approach to handle this entirely withsharp? If I understand correctly, it would let me flag the raw image data as already premultiplied, though I'm unsure if that would prevent me from needing to unpremultiply after merging the alpha channel.Thank you for your time and guidance.