How can I add an image to the specific layer of psd file using ag-psd module in react project?

166 Views Asked by At

I am gonna add an image to the specific layer of psd file using ag-psd module in react project. In other words, I want to add an image as the cover of book. See this image, please.

image of work in progress

const replacelayerName = 'replace';
const replacelayer = psd.children.find((child) => child.name === replacelayerName);

if (replacelayer && replacelayer.canvas) {
    const myImage = await loadImage(URL.createObjectURL(imageFile));
    replacelayer.canvas.width = myImage.width;
    replacelayer.canvas.height = myImage.height; 
    replacelayer.canvas.getContext('2d').drawImage(myImage, 0, 0);
        
const newPsd = writePsd(psd);

...

*setMockupPreview(newPsd.canvas.toDataURL());* Here error occurs.
0

There are 0 best solutions below