-
Notifications
You must be signed in to change notification settings - Fork 68
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
How to add a image to a layer? #38
Comments
Hi @hittang you can try the below code, let me know if that can help you, cheers. from photoshop import Session
with Session(action="new_document") as ps:
desc = ps.ActionDescriptor
desc.putPath(ps.app.charIDToTypeID("null"), "your/image/path.jpg")
event_id = ps.app.charIDToTypeID("Plc ") # `Plc` need one space in here.
ps.app.executeAction(event_id, desc) |
Thank you ,i will try the code, and tell you the result. another question, can you show a sample how to replace an image of layer by a new image with same size? or ,where the document or tutorial of your above code . tks again |
@hittang I usually search for the corresponding javascript fragment in google or get the javascript from ScriptingListener and then convert it use into python code use the below code is replacing the current active image layer of the active document. If the size of the two pictures is the same, there is no need to consider the size issue. If they are not the same, you may have to get the original picture size and replace it with a new picture and then resize it again. Code from ScriptingListener
PYPS from photoshop import Session
with Session() as ps:
idplacedLayerReplaceContents = ps.app.stringIDToTypeID("placedLayerReplaceContents")
desc = ps.ActionDescriptor
idnull = ps.app.charIDToTypeID("null")
desc.putPath(idnull, "your/image/file.jpg")
ps.app.executeAction(idplacedLayerReplaceContents, desc) |
Hi @hittang I just want to confirm that is all works for you? |
Hi, is there a way i can change the image on a specific layer? Thanks |
@ConnorCampagnaDeveloper |
for instance if I have a layer called "Player" and i have another layer called "Game", they both contain images, but i want to change the image of both these to 2 another 2 images. so instead of me changing the image on the active layer i would like to change it on another layer which i do not have selected. Thanks :) |
Just realised i have not made that the clearest, basically what im trying to do is change an image on a layer that is not the active one selected. click on image to see context of caption below for example i would like to change the image in the SFC layer(context in image) |
Hello!! File "C:\Python39\lib\site-packages\comtypes\automation.py", line 745, in _invoke Any idea why it could be? |
hello when i manually do this in photoshop it works fine(i dont have to do any placement because it is exactly as same pixel as layer), but when i do it through the code, the photo becomes more wider than i thought code i used -- i am attaching results for reference - |
How to add a image onto a layer? How to change a image of a layer? Thanks
The text was updated successfully, but these errors were encountered: