<wand.img> saving several png files as photoshop psd file converts the color into grayscale

84 Views Asked by At
from wand.image import Image

with Image(filename="base.png") as img:
    img.read(filename="background.png")
    img.read(filename="image.png")
    img.read(filename="sub_box.png")
    img.read(filename="cta_box.png")
    img.read(filename="sub_text.png")
    img.read(filename="cta_text.png")
    img.save(filename="final.psd")

I wrote this code to stack png images into a psd file

The code does work, the file has all the layers, but the color is all grayscale (png images aren't grayscale)

https://docs.wand-py.org/en/0.6.13/wand/image.html

Any ideas for solving this problem?

I tried to change the image.format to psd, checked the image.colorspace but couldn't solve the problem

2

There are 2 best solutions below

2
sefecesence On

The problem was quite simple:

When I changed the code like this,

with Image(filename="base.png") as img:
    img.read(filename="base.png")
    img.read(filename="background.png")
    img.read(filename="image.png")
    img.read(filename="sub_box.png")
    img.read(filename="cta_box.png")
    img.read(filename="sub_text.png")
    img.read(filename="cta_text.png")
    img.save(filename="final.psd")

It solved the issue

I guess you should first read the file you opened for some reason

4
Arunbh Yashaswi On
from wand.image import Image

with Image() as img:
    with Image(filename="base.png") as base:
        img.composite(base, 0, 0)
    layer_img_pth= ["background.png", "image.png", "sub_box.png", "cta_box.png", "sub_text.png", "cta_text.png"]
    for layer in layer_img_pth:
        with Image(filename=layer) as layer_img:
            img.composite(layer_img, 0, 0)
    img.format = 'psd'
    img.save(filename="final.psd")

This will help you stack images one over other. Also if have examples of files please attach it to question itself.