new to the site and beginner level user of Python. I am attempting to automate this process for the use of editing normal maps. Setting the blue channel to black or white makes it compatible/incompatible for certain games/programs. There are many similar questions regarding the editing of channels of an image, but none specifically pertain to setting a channel to any specific color. Also to clarify, I am not looking to simply invert the image either. This is because some blue channels of normal maps have black and white pixels, so inverting would not solve the issue.
import glob
import PySimpleGUI as sg
import photoshop.api as PS
from photoshop import Session
def Automate():
app = PS.Application('version 23')
for file in glob.glob(values['TARGET_FOLDER']):
with Session() as ps:
ps.app.load(file)
doc = ps.active_document
I've gotten to the point where I can open up PS and load a file. This was a good start. However, I have not been able to edit the blue channel of the file through any means involving the original api library. Is there a way to edit the blue channel filling it completely with the color White, using this library or any other library such as Pillow?
CodePudding user response:
Try to use im.split to get each rgb bands, create a new blue band by Image.new with white or black color, then Image.merge R, G and new B bands. (Library Pillow).
Example code
from PIL import Image
im = Image.new('RGBA', (10, 10), (255,255,255,255))
r, g, b, a = im.split()
b = Image.new('L', (10, 10), 0)
new = Image.merge('RGBA', (r, g, b, a))
new.show()