Comments (10)
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)
from photoshop-python-api.
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
from photoshop-python-api.
@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 photoshop-python-api
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
var idplacedLayerReplaceContents = stringIDToTypeID( "placedLayerReplaceContents" );
var desc93 = new ActionDescriptor();
var idnull = charIDToTypeID( "null" );
desc93.putPath( idnull, new File( "C:\\Users\\hao.long\\Pictures\\HAL-1.png" ) );
executeAction( idplacedLayerReplaceContents, desc93, DialogModes.NO );
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)
from photoshop-python-api.
Hi @hittang I just want to confirm that is all works for you?
from photoshop-python-api.
Hi, is there a way i can change the image on a specific layer? Thanks
from photoshop-python-api.
Hi, is there a way i can change the image on a specific layer? Thanks
@ConnorCampagnaDeveloper
Do you give me more contextual information?
Do you mean to replace the image by replacing the layer?
from photoshop-python-api.
Hi, is there a way i can change the image on a specific layer? Thanks
@ConnorCampagnaDeveloper
Do you give me more contextual information?
Do you mean to replace the image by replacing the layer?
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 :)
from photoshop-python-api.
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)
from photoshop-python-api.
@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
photoshop-python-api
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
var idplacedLayerReplaceContents = stringIDToTypeID( "placedLayerReplaceContents" ); var desc93 = new ActionDescriptor(); var idnull = charIDToTypeID( "null" ); desc93.putPath( idnull, new File( "C:\\Users\\hao.long\\Pictures\\HAL-1.png" ) ); executeAction( idplacedLayerReplaceContents, desc93, DialogModes.NO );
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)
Hello!!
I'm trying to use the code to load images in a layer but it doesn't work for me.
I get the following error:
File "C:\Python39\lib\site-packages\comtypes\automation.py", line 745, in _invoke
self.__com_Invoke(memid, riid_null, lcid, invkind,
_ctypes.COMError: (-2147212704, None, (None, None, None, 0, None))
Any idea why it could be?
Thanks!!!
from photoshop-python-api.
hello
i am doing same thing , i tried both of your codes, but in my case i am using exactly same image as layer holder,
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 --
with Session(mockup, action="open",auto_close=True) as ps: active_layer = ps.active_document.activeLayer bounds = active_layer.bounds # in this segment we are getting the frame of mockup, then we use # our function to adjust the image within given pixel without distortion width = int(bounds[2] - bounds[0]) height = int(bounds[3] - bounds[1]) adjust_image()# i replace my image here with same width and height as layer replace_contents = ps.app.stringIDToTypeID("placedLayerReplaceContents") desc = ps.ActionDescriptor idnull = ps.app.charIDToTypeID("null") desc.putPath(idnull, 'img.png') ps.app.executeAction(replace_contents, desc) ps.active_document.saveAs(f'res.jpg', ps.JPEGSaveOptions())
i am attaching results for reference -
using code -
manually -
mockup file i used - link
from photoshop-python-api.
Related Issues (20)
- 如何使用这个api调整笔刷旋转角度 HOT 1
- How to Replace Smart Layer Text with a Script
- How to hide the Photoshop window
- How to adjust HDR Toning
- Photoshop API with python multithreading HOT 2
- How to import data group txt file and export data group as file
- 无法在mac 电脑上使用 建议兼容一下 HOT 2
- `slelect` method is missing in Code Reference HOT 1
- About the bottomed API reference HOT 1
- Replacing multiple layers with images does not work; it only replaces the same layer multiple times
- PSB Save options available?
- How to get the rotation angle of a layer
- Can I give an example of applying gradients to a text layer style HOT 3
- How to import Images into Document
- 希望可以添加 接受 ps 消息弹框的 接口,如 缺失字体等等 HOT 5
- 请问如何给字体导入外部字体包 How can I import the font package externally? HOT 5
- 请问如何将多个psd以画板的形式合成为一个psd How to synthesize multiple psd into one psd in the form of sketchpad?
- 可以同时操作两个ps 吗? HOT 3
- export_layers_use_export_options_saveforweb donesn't work HOT 1
- 替换图片 能替换成功,但是控制台输出错误 发生意外。', ('非法参数 - 参数 1\n- 缺少必需值' HOT 3
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from photoshop-python-api.