-
Notifications
You must be signed in to change notification settings - Fork 75
Open
Description
Description:
I am encountering issues when attempting to convert an RGB image to CMYK and then export the resulting CMYK image using image-js. None of the export methods work after performing the CMYK conversion, and they throw errors related to the number of channels. This seems to be an issue with handling CMYK, which has 4 color channels. Below are the details of the errors, example code, and steps to reproduce the issue.
Steps to Reproduce:
- Load an RGB image using
Image.load(). - Convert the image to CMYK using
image.cmyk(). - Try to export the CMYK image using any of the following methods:
toBase64('image/jpeg')toBlob('image/png')toDataURL()toBuffer()
Example Code:
import { Image } from 'image-js';
// Load and convert an image from RGB to CMYK
const processImage = async (imageUrl) => {
try {
const image = await Image.load(imageUrl);
const cmykImage = image.cmyk();
// Trying to export the CMYK image to different formats
const base64Output = await cmykImage.toBase64('image/jpeg');
console.log(base64Output); // This throws an error
const blobOutput = await cmykImage.toBlob('image/png');
console.log(blobOutput); // This throws an error
} catch (err) {
console.error('Error processing the image:', err);
}
};
// Example usage
processImage('path/to/image.jpg');Error 1 (toBase64 with image/jpeg):
Error: The process: getRGBAData can only be applied if the number of components is in: 1,3
Error 2 (toBlob with image/png):
PngEncoder.ts:156 Uncaught (in promise) RangeError: unsupported number of channels: 5
at getColorType (PngEncoder.ts:156:1)
Metadata
Metadata
Assignees
Labels
No labels