Code Monkey home page Code Monkey logo

photoshop-python-api's Introduction

logo

python version PyPI version Downloads Status Downloads License pypi format Chat on Discord Maintenance Bump version pages-build-deployment Documentation Status photoshop-2024 photoshop-2023 photoshop-2022 photoshop-2021 photoshop-2020 photoshop-CC2019 photoshop-CC2018 photoshop-CC2017

All Contributors

Python API for Photoshop.

The example above was created with Photoshop Python API. Check it out at https://loonghao.github.io/photoshop-python-api/examples.

Has been tested and used Photoshop version:

Photoshop Version Supported
2023
2022
2021
2020
cc2019
cc2018
cc2017

Installing

You can install via pip.

pip install photoshop_python_api

Since it uses COM (Component Object Model) connect Photoshop, it can be used in any DCC software with a python interpreter.

Hello World

import photoshop.api as ps
app = ps.Application()
doc = app.documents.add()
new_doc = doc.artLayers.add()
text_color = ps.SolidColor()
text_color.rgb.red = 0
text_color.rgb.green = 255
text_color.rgb.blue = 0
new_text_layer = new_doc
new_text_layer.kind = ps.LayerKind.TextLayer
new_text_layer.textItem.contents = 'Hello, World!'
new_text_layer.textItem.position = [160, 167]
new_text_layer.textItem.size = 40
new_text_layer.textItem.color = text_color
options = ps.JPEGSaveOptions(quality=5)
# # save to jpg
jpg = 'd:/hello_world.jpg'
doc.saveAs(jpg, options, asCopy=True)
app.doJavaScript(f'alert("save to jpg: {jpg}")')

demo

Photoshop Session

Use it as context.

from photoshop import Session


with Session(action="new_document") as ps:
    doc = ps.active_document
    text_color = ps.SolidColor()
    text_color.rgb.green = 255
    new_text_layer = doc.artLayers.add()
    new_text_layer.kind = ps.LayerKind.TextLayer
    new_text_layer.textItem.contents = 'Hello, World!'
    new_text_layer.textItem.position = [160, 167]
    new_text_layer.textItem.size = 40
    new_text_layer.textItem.color = text_color
    options = ps.JPEGSaveOptions(quality=5)
    jpg = 'd:/hello_world.jpg'
    doc.saveAs(jpg, options, asCopy=True)
    ps.app.doJavaScript(f'alert("save to jpg: {jpg}")')

Contributors ✨

Thanks goes to these wonderful people (emoji key):

Hal
Hal

💻
voodraizer
voodraizer

🐛
brunosly
brunosly

🐛
tubi
tubi

🐛
wjxiehaixin
wjxiehaixin

🐛
罗马钟
罗马钟

🐛
clement
clement

🐛
krevlinmen
krevlinmen

🐛
Thomas
Thomas

🐛
CaptainCsaba
CaptainCsaba

🐛
Il Harper
Il Harper

💻
blunderedbishop
blunderedbishop

🐛
MrTeferi
MrTeferi

💻
Damien Chambe
Damien Chambe

💻
Ehsan Akbari Tabar
Ehsan Akbari Tabar

🐛
Michael Ikemann
Michael Ikemann

🐛
Enguerrand DE SMET
Enguerrand DE SMET

💻
Proton
Proton

💻

This project follows the all-contributors specification. Contributions of any kind are welcome!

Repobeats analytics

Repobeats analytics

how to get Photoshop program ID

Get-ChildItem "HKLM:\SOFTWARE\Classes" | 
  ?{ ($_.PSChildName -match "^[a-z]+\.[a-z]+(\.\d+)?$") -and ($_.GetSubKeyNames() -contains "CLSID") } | 
  ?{ $_.PSChildName -match "Photoshop.Application" } | ft PSChildName

get_program_id

How to get a list of COM objects from the registry

Useful links

photoshop-python-api's People

Contributors

actions-user avatar allcontributors[bot] avatar damienchambe avatar dependabot[bot] avatar dsmte avatar feisuzhu avatar github-actions[bot] avatar ilharp avatar investigamer avatar loonghao avatar renovate-bot avatar renovate[bot] avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

photoshop-python-api's Issues

I can't download the package on pycharm

I want to install the package on pycharm, but it doesn't install.
I used both pycharm and command prompt to install the package, but it outputs an error like ERROR: Command errored out with exit status 1:

How the error occured

  1. Go to 'python package' in pycharm
  2. Click on 'install photoshop-python-api'
  3. See an error like Installing packages failed: Installing packages: error occurred
    command prompt (admin)
  4. Specify the path to the script location in pycharm
  5. Enter pip install photoshop-python-api
  6. An error like error: error in setup script: command 'bdist_wininst' has no such option 'install_script'

Expected behavior
Like most packages, pycharm will output a success message indicating that the package is installed successfully and can be used, and no error will output when trying to import the package in python script.

Screenshots
What pycharm outputs:
image
What command prompt outputs:
image

Desktop:

  • OS: Windows 10 Home
  • Photoshop Version: Photoshop 2021
  • Python Version: Python 3.8

Additional context
I am not sure whether my domain is in China and the internet is not stable to access a foreign environment or others, but I think GitHub doesn't require VPN. Maybe I will try to install from website next time.

Can't save in psd

Hello. I did a little script that save's every layer as an png file, but I would like to make it able to save in PSD.

I tried using PhotoshopSaveOptions instead of PNGSaveOptions but it just return some errors.

This is my working PNG code.

import photoshop as ps
import os

def main():
    app = ps.Application()
    doc = app.activeDocument()
    i = 0
    for y in doc.artLayers:
        j = 0
        for x in doc.artLayers:
            if i == j:
                x.visible = True
            else:
                x.visible = False
            j = j + 1
        i = i+1
        options = ps.PNGSaveOptions()
        if not os.path.exists(doc.path + '/' + y.name):
            os.mkdir(doc.path + '/' + y.name)
        imagepath = doc.path + '/' + y.name + '/' + y.name + '.png'
        doc.saveAs(imagepath, options, True)
    app.doJavaScript(f'alert("Task done!")')
    print(doc.activeLayer)

if __name__ == '__main__':
    main()`

If I use ps.PhotoshopSaveOptions() instead of ps.PNGSaveOptions() it will give this error.

Traceback (most recent call last):
File "C:/Users/bruno.freitas/Desktop/PhotoshopLayer/Main.py", line 26, in
main()
File "C:/Users/bruno.freitas/Desktop/PhotoshopLayer/Main.py", line 17, in main
options = ps.PhotoshopSaveOptions()
AttributeError: module 'photoshop' has no attribute 'PhotoshopSaveOptions'

Process finished with exit code 1

And if I use ps.save_options.PhotoshopSaveOptions() instead of ps.PNGSaveOptions() it will give this error.

Traceback (most recent call last):
File "C:/Users/bruno.freitas/Desktop/PhotoshopLayer/Main.py", line 26, in
main()
File "C:/Users/bruno.freitas/Desktop/PhotoshopLayer/Main.py", line 21, in main
doc.saveAs(imagepath, options, True)
File "C:\Users\bruno.freitas\AppData\Local\Programs\Python\Python38-32\lib\site-packages\comtypes\client\lazybind.py", line 182, in caller
return self._comobj._invoke(descr.memid, descr.invkind, 0, *args)
File "C:\Users\bruno.freitas\AppData\Local\Programs\Python\Python38-32\lib\site-packages\comtypes\automation.py", line 728, in _invoke
self.__com_Invoke(memid, riid_null, lcid, invkind,
_ctypes.COMError: (-2147220261, None, (None, None, None, 0, None))

Process finished with exit code 1

I'm new to Python and not a pro programmer, so there's a great possibility that I'm just doing something very wrong. Can someone help me

I can't open the psd file, I get an error when I run it

import os

from photoshop import Session


def hide_all_layers(layers):
    for layer in layers:
        layer.visible = False


def main():
    psd_file = 'demo1.psd'
    with Session(psd_file, action="open") as ps:
        doc = ps.active_document
        options = ps.PNGSaveOptions()
        layers = doc.artLayers
        for layer in layers:
            hide_all_layers(layers)
            layer.visible = True
            layer_path = os.path.join(doc.path, layer.name)
            print(layer_path)
            if not os.path.exists(layer_path):
                os.makedirs(layer_path)
            image_path = os.path.join(layer_path, f"{layer.name}.png")
            doc.saveAs(image_path, options, True)
        ps.alert("Task done!")
        ps.echo(doc.activeLayer)


if __name__ == "__main__":
    main()

tips:

_ctypes.COMError: (-2147220262, None, (None, None, None, 0, None))

I get an error running directly from the library when I use the documentation:
https://photoshop-python-api.readthedocs.io/en/0.15.1/examples.html#export-layers-as-png

Get text layer font size incorect

Describe the bug
psdfile.zip

There is two Text layer in the psd file, when I get the font size,
one of the font size value is right, the other one is wrong, but in Photoshop, they are both 48

layername: wrong font_size: 22.33272933959961
layername: right font_size: 48.0

by the way how to get the text width? I can't get the layer.textItem.width value

To Reproduce
Steps to reproduce the behavior:

import photoshop.api as ps
app = ps.Application()
doc = app.load(r'C:\1.psd')
for layer in doc.layers:
print('layername:', layer.name, 'font_size:', layer.textItem.size)
doc.close()

Desktop (please complete the following information):

  • OS: Windows10,
  • Photoshop Version: Photoshop-2021
  • Python Version: python-3.9.5

Visible flag for layers set not wotk.

Hi,
I'm trying to set a visibility property to LayerSet, but nothing happens
docRef.layerSets[0].visible = False

For art layers this work fine.

Windows10, Photoshop v.21, Python 3.7.2

Cannot download photoshop_python_integration

Hello, I want to download photoshop_python_integration. But when I click the download, I got a message that "Please contact the file owner and ask him to grant you access".
How I can download it?

Why does textItem.autoKerning/autoLeadingAmount report errors when using?

layer_1.textItem.useAutoLeading = 1000
File "C:\Python3\lib\site-packages\photoshop\api\text_item.py", line 598, in useAutoLeading
self.app.useAutoLeading = value
File "C:\Python3\lib\site-packages\comtypes\client\lazybind.py", line 218, in setattr
self._comobj._invoke(descr.memid, descr.invkind, 0, value)
File "C:\Python3\lib\site-packages\comtypes\automation.py", line 728, in _invoke
self.__com_Invoke(memid, riid_null, lcid, invkind,
_ctypes.COMError: (-2147220276, None, (None, None, None, 0, None))

TextLayer.kind and TextLayer.justification properties don't exist

I wrote this code:

def writeLayer(text):
txtLayer = doc.artLayers.add()
txtLayer.kind = ps.LayerKind.TextLayer
txtLayer.textItem.contents = text
txtLayer.textItem.kind = ps.TextType.ParagraphText
txtLayer.textItem.justification = ps.Justification.Center

The problem is, the last 2 properties don't appear on Visual Code auto-complete, neither change anything in the new photoshop layer after executing the code.
Also, the constants do appear on Visual Code, only the properties themselves that don't.

I used the Photoshop JS scripting guide to figure out both of these properties:
https://wwwimages.adobe.com/www.adobe.com/content/dam/acom/en/devnet/photoshop/pdfs/photoshop-cc-javascript-ref-2015.pdf#G4.368374

how to call Ps2021?

Describe the bug
I have installed 2 version of PS , one is 2017 another is 2021. When I run my code in pycharm,the older version will be called.
So I uninstalled the 2017 version,but when I run my code again,the PS cann't be called.
Then I opened the 《constants.py》 and add "2021:150" in its dictionary, but i still cann't slove the problem.

To Reproduce

import photoshop.api as ps app = ps.Application(version='2021')
I receved this Error:
`Traceback (most recent call last):
File "C:\Users\LJY\AppData\Local\Programs\Python\Python39\lib\site-packages\photoshop\api_core.py", line 33, in init
self.app = self.instance_app(self.app_id)
File "C:\Users\LJY\AppData\Local\Programs\Python\Python39\lib\site-packages\photoshop\api_core.py", line 109, in instance_app
return CreateObject(self.program_name, dynamic=True)
File "C:\Users\LJY\AppData\Local\Programs\Python\Python39\lib\site-packages\comtypes\client_init
.py", line 227, in CreateObject
clsid = comtypes.GUID.from_progid(progid)
File "C:\Users\LJY\AppData\Local\Programs\Python\Python39\lib\site-packages\comtypes\GUID.py", line 78, in from_progid
_CLSIDFromProgID(str(progid), byref(inst))
File "_ctypes/callproc.c", line 947, in GetResult
OSError: [WinError -2147221005] 无效的类字符串

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
File "C:\Users\LJY\AppData\Local\Programs\Python\Python39\lib\site-packages\photoshop\api_core.py", line 36, in init
self.app = self.instance_app(self._get_program_id())
File "C:\Users\LJY\AppData\Local\Programs\Python\Python39\lib\site-packages\photoshop\api_core.py", line 109, in instance_app
return CreateObject(self.program_name, dynamic=True)
File "C:\Users\LJY\AppData\Local\Programs\Python\Python39\lib\site-packages\comtypes\client_init
.py", line 227, in CreateObject
clsid = comtypes.GUID.from_progid(progid)
File "C:\Users\LJY\AppData\Local\Programs\Python\Python39\lib\site-packages\comtypes\GUID.py", line 78, in from_progid
_CLSIDFromProgID(str(progid), byref(inst))
File "_ctypes/callproc.c", line 947, in GetResult
OSError: [WinError -2147221005] 无效的类字符串

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
File "W:\00000-LJY\colorplan\jaye-p.py", line 3, in
doc = app.documents.add()
File "C:\Users\LJY\AppData\Local\Programs\Python\Python39\lib\site-packages\photoshop\api_core.py", line 61, in getattribute
return super().getattribute(item)
File "C:\Users\LJY\AppData\Local\Programs\Python\Python39\lib\site-packages\photoshop\api\application.py", line 134, in documents
return Documents(self.app.documents)
File "C:\Users\LJY\AppData\Local\Programs\Python\Python39\lib\site-packages\photoshop\api_documents.py", line 13, in init
super().init(parent=parent)
File "C:\Users\LJY\AppData\Local\Programs\Python\Python39\lib\site-packages\photoshop\api_core.py", line 38, in init
raise PhotoshopPythonAPIError(
photoshop.api.errors.PhotoshopPythonAPIError: Please check if you have Photoshop installed correctly.`

Expected behavior
I want my ps can be called

Screenshots
If applicable, add screenshots to help explain your problem.
image

Desktop (please complete the following information):

  • OS: [e.g. Windows10,]
  • Photoshop Version: [e.g. Photoshop-2021]
  • Python Version: [e.g. python-3.9]

Additional context
thank you for your solution。

support for python 3.4

Only the use of f-strings prohibits the use of this library on python versions lower than 3.6.

A S&R over all files easily remedies this. Likely there are more elegant solutions, for f-strings are by no means essential.

used regex-patterns:

find: f'(.+)'
repl: '\1'.format(**locals())

find: f"(.+)"
repl: "\1".format(**locals())

Getting Windows error "FileNotFoundError"

Just installed the package and copied the exact usage example from the docs (active layer). Windows throws this WinError 2 error because apparently I have a 32 bits Python and it's looking for Photoshop as if it was also 32 bits (which is is not) according to this stack overflow issue.

Using the suggested answer of adding the argument access=winreg.KEY_READ | winreg.KEY_WOW64_64KEY inside the function _get_install_version in _core.py worked for me.

key = winreg.OpenKey(
        winreg.HKEY_LOCAL_MACHINE,
        self.REG_PATH,
        access=winreg.KEY_READ | winreg.KEY_WOW64_64KEY
)

Just in case:
Using Windows 10, Python 3.7 and version 0.6.0 of this package.

Add `action` and `callback` options on `Session`

from photoshop import Session

def do_something():
      print("Do something.")

with Session("your/psd/file/path.psd", document_action="open", callback=do_something) as ps:
        print(ps.active_document.name)

_ctypes.COMError

Describe the bug
I want to rasterize all layers imported from PDF,but i received :
_ctypes.COMError: (-2147352577, '出现了内部错误。', (None, None, None, 0, None))

To Reproduce
my code:
for j in doc.layers: j.rasterize(target=5)

the tracebake:
image

Desktop (please complete the following information):

  • OS: [e.g. Windows10]
  • Photoshop Version: [e.g. Photoshop-2021]
  • Python Version: [e.g. python-3.9]

Additional context
thanks for your solution!

fill selection with the content-aware option

Is there an API I can use to invoke the fill selection with the content-aware option,
or I have to wrap the photoshop javascript inside the app.doJavaScript ?

Javascript snippets from the ScriptingListenerJS.log after install the Adobe ScriptListener plug-in:

var idFl = charIDToTypeID( "Fl  " );
    var desc295 = new ActionDescriptor();
    var idUsng = charIDToTypeID( "Usng" );
    var idFlCn = charIDToTypeID( "FlCn" );
    var idcontentAware = stringIDToTypeID( "contentAware" );
    desc295.putEnumerated( idUsng, idFlCn, idcontentAware );
    var idcontentAwareColorAdaptationFill = stringIDToTypeID( "contentAwareColorAdaptationFill" );
    desc295.putBoolean( idcontentAwareColorAdaptationFill, false );
    var idcontentAwareRotateFill = stringIDToTypeID( "contentAwareRotateFill" );
    desc295.putBoolean( idcontentAwareRotateFill, false );
    var idcontentAwareScaleFill = stringIDToTypeID( "contentAwareScaleFill" );
    desc295.putBoolean( idcontentAwareScaleFill, false );
    var idcontentAwareMirrorFill = stringIDToTypeID( "contentAwareMirrorFill" );
    desc295.putBoolean( idcontentAwareMirrorFill, false );
    var idOpct = charIDToTypeID( "Opct" );
    var idPrc = charIDToTypeID( "#Prc" );
    desc295.putUnitDouble( idOpct, idPrc, 100.000000 );
    var idMd = charIDToTypeID( "Md  " );
    var idBlnM = charIDToTypeID( "BlnM" );
    var idNrml = charIDToTypeID( "Nrml" );
    desc295.putEnumerated( idMd, idBlnM, idNrml );
executeAction( idFl, desc295, DialogModes.NO );

Error if enter version

Describe the bug

An error appears if you enter the photoshop version in the api.

To Reproduce

If i set version number like this:

import photoshop.api as ps
app = ps.Application(version="2020")

It gave me this error:

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "C:\Python37\lib\site-packages\photoshop\api\application.py", line 34, in __init__
    super().__init__(ps_version=version)
  File "C:\Python37\lib\site-packages\photoshop\api\_core.py", line 32, in __init__
    self.app = self.instance_app(self.app_id)
  File "C:\Python37\lib\site-packages\photoshop\api\_core.py", line 108, in instance_app
    self._program_name = self._assemble_program_name(naming_space)
  File "C:\Python37\lib\site-packages\photoshop\api\_core.py", line 153, in _assemble_program_name
    return ".".join(names)
TypeError: sequence item 2: expected str instance, int found

** To resolve **
Change the content of the file constant.py by:

# The photoshop version to COM progid mappings.
PHOTOSHOP_VERSION_MAPPINGS = {
    "2020": "140",
    "2019": "130",
    "2018": "120",
    "2017": "110",
    "2017": "110",
    "CS4": "11"
}

Desktop :

  • OS: [e.g. Windows10]
  • Photoshop Version: [Photoshop-2020/Photoshop-CS4]
  • Python Version: [python-3.7]

Run outside python IDE of photoshop

I am looking into ways to automate photoshop scripting and stumbled on this library.
The example gif shows this library running from within photoshop. Is it possible to run the API from outside the IDE in the following way:

  1. Open photoshop programatically
  2. Adjusts text layers using photoshop-python-api
  3. Save to new psd file

Also, would this work on mac as well or only Windows?

Many thanks for answering!

how to imprt PDF files correctly

deer author:
I cannt undersatand the meaning of this row :
image
The variable 'event_id' is not referenced by any thing,but when I copied this example in my pycharm,it showed like that have be referenced.
And in my progress,I commented out this line of code,the program can also be runned successfully,so what's the meaning of it?
image
Though I used the methord in example 'Import Image As Layer' to import my PDF files as layers successfully, I want to make sure that if have the proprietary event id for importing PDF.
I also want to know why the 《event_id.py》donnt have the value 'null',but the putPath-methord's parameter 'ps.app.charIDToTypeID("null")' can be readed correctly?
image
image

Thanks for your answer!

@loonghao

how can change different style in one textlayer

There is a textlayer,The text is 'good job,bro~!'
I want to change 'good job' color to red , 'bro~!' to green,
Maybe change the font or orther styles
In Photoshop I can edit the style easily, but how do I edit it in photoshop-python-api?

  • OS: Windows10
  • Photoshop Version: Photoshop-202
  • Python Version: python-3.9.7

how does jsx load python code (addfilter.py) directly not in cmd window

Dear author,
First, thanks for your great job.
The pythonIDE is good for developers, but in fact for users they just want click on button and get the result they want and they do not know what is python.
If I do not want to show the cmd window and I want the jsx file runs or loads the python code (addfilter.py) directly and show the result in photoshop, what I should do?
Or is there any references to learn how to do this?
I search on internet, but it has few information about how jsx connects with python or loads python.

The package <comtypes> cannot support python3.x?

Hello,
I download your api on pycharm, and it contain comtypes 1.1.7, but comtypes may be not compatible with python3.x . I try to use pypiwin32 as COM but fails. So it just support python2?

How to modify color fill layer

Hi guys,

I want to change color of fill layer. I just tried change color by selection.fill but app return error: The command Fill is not current available.

here my code:
`colorObj = Dispatch("Photoshop.SolidColor")
colorObj.RGB.Red = rgb_strip[0]
colorObj.RGB.Green = rgb_strip[1]
colorObj.RGB.Blue = rgb_strip[2]

                    art_file.Selection.Fill(colorObj)`

TypeError: '_Dispatch' object is not callable

Describe the bug
i run this example code:
`import photoshop.api as ps

app = ps.Application()
doc = app.documents.add()
new_doc = doc.artLayers.add()`

but :
Traceback (most recent call last): File "W:\00000-LJY\colorplan\jaye-p.py", line 4, in <module> doc = app.documents.add() File "C:\Users\LJY\AppData\Local\Programs\Python\Python39\lib\site-packages\photoshop\api\_documents.py", line 49, in add self.app.add( TypeError: '_Dispatch' object is not callable

may the 'add' methord cann't attachde to the object 'doc',how can i repair it?

Desktop (please complete the following information):

  • OS: [ Windows10]
  • Photoshop Version: [ Photoshop-2020]
  • Python Version: [python-3.9]

Additional context
thank you for your solution

How to crop a Image?

How do I crop an image? I have trouble finding arguments for cropping an image. Thank you

Color Settings / Load Color profile

Describe the bug
Is there a way to create a Custom CMYK Color profile and later load it?
By hand I do it in here
image

where I can set the values for Dot Gain, Separation Type, ...
however, I haven't seen a sample on how to do it using the python wrapper.
thx!

P.S. Otherwise a very good library!

Can't get doc.channels length

len(doc.channels)
this line raise error TypeError: object of type 'Dispatch' has no len()

Windows10, Photoshop v.21, Python 3.7.2

Installation difficulties

Hello. I am trying to install the package via various means described in the documentation. None of them have worked for some reason. I would love to use your package, that is why I am writing this. If this is a noob mistake on my part, I apologise in advance.

If I install the package via the 'pip install python_photoshop_api' command it does not actually gets installed. If I navigate to my Python39/Lib/site-packages/photoshop_python_api-0.16.0.dist-info directory there are these files present, but no .py files that could actually be imported:

INSTALLER
LICENSE
METADATA
RECORD
REQUESTED
WHEEL

Thus I'm getting the "ModuleNotFoundError: No module named 'photoshop'".

If I try to install it via the tarball, the link is taking me to a Github error 404 page.

I also tried GIT cloning. I've placed the downloaded folder into my Python39/Lib/site-packages directory. I've tried to import session via the 'from photoshop_python_api.src.photoshop.session import Session' command but it still gives me the "ModuleNotFoundError: No module named 'photoshop'".

Additional info:

  • I have downloaded many other packages over the past months via pip install, all are importable.
  • There are no environments.
  • Photoshop 2021 is installed. Adobe Photoshop Version: 22.1.0 20201125.r.94
  • I am using Python 3.9.1.
  • I am using Windows 10.
  • There are also no other versions of Python installed, so I have just 1 interpreter.
  • For editing I am using VS Code.

How come I can't install the package?

Some SaveOptions tuning missing.

Hi,
I'm trying to save tga but it's not implemented. Like this TargaSaveOptions().

Also can't find how to set bits for save image (in 'js-code' saveOptions.resolution = TargaBitsPerPixels.THIRTYTWO)

Documents Class not subscriptable

Describe the bug
The "documents" class is supposed to be subscriptable but the class seems to be missing the "getitem()" method required to do so.

To Reproduce
Steps to reproduce the behavior:
import photoshop.api as ps
app = ps.Application()
app.documents[0]

Expected behavior
The following error should be returned:

"Traceback (most recent call last):
File "", line 1, in
TypeError: 'Documents' object is not subscriptable"

Screenshots
image

Desktop (please complete the following information):

  • OS: Windows10 Pro
  • Photoshop Version: Adobe Photoshop Version: 21.2.2 20200807.r.289 2020/08/07: 287d0d87ec x64
  • Python Version: Python 3.8.3

Additional context
Please see Photoshop Scripting documentation on "Documents" class.
https://theiviaxx.github.io/photoshop-docs/Photoshop/Documents.html

> > Hi, is there a way i can change the image on a specific layer? Thanks

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 :)

Originally posted by @ConnorCampagnaDeveloper in #38 (comment)

AttributeError: module 'photoshop.api' has no attribute 'LayerKind'

Describe the bug
when i run photoshop-python-api-master\examples\hello_world.py

full log

Traceback (most recent call last):
File "hello_world.py", line 22, in
hello_world()
File "hello_world.py", line 10, in hello_world
new_text_layer.kind = ps.LayerKind.TextLayer
AttributeError: module 'photoshop.api' has no attribute 'LayerKind'

my py version 3.7.4

TypeError: '_Dispatch' object is not callable

Running example(s) returns errors. Windows 10, Photoshop CC 2017, Python 3.8.7.

>> python3 session_hello_world.py

Traceback (most recent call last):
  File "session_hello_world.py", line 9, in <module>
    doc = adobe.app.documents.add(2000, 2000)
  File "C:\Users\marco\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.8_qbz5n2kfra8p0\LocalCache\local-packages\Python38\site-packages\photoshop_python_api-0.14.0-py3.8.egg\photoshop\api\_documents.py", line 47, in add
TypeError: '_Dispatch' object is not callable

Contact Sheet

Bug Discription:

The problem I'm experiencing is with the Application.makeContactSheet command. According to the documentation it has two arguments. An array of files (paths to all images that need to be on the contact sheet), and an array of options. However I've never been able to make it work.

Here is what I'm currently trying to do:

import photoshop.api as ps
from win32com.client import Dispatch
from os import path, walk
import inspect

dispatch = Dispatch("Photoshop.Application")  #Open PS
api = ps.Application()  #Application Object
Source = "Path to folder with all files"

files = [path.join(r,f) for r, sd, fs in walk(Source) for f in fs]  #Making an array of paths
options = [True, psApp, False, False, 6, True, None, 0, 7, 4, 3, 300, 3, None, True]

api.makeContactSheet(files , options )

I suspect that options array is incorrect, because I get this error:
Illegal argument - argument 2\n- Object expected

I then decided to remove this array (Still not sure what I did wrong). Which helped me get as far as opening the Contact Sheet Dialog Window. However as you can see from the screenshot below, no files were selected.

Screenshot 2021-08-27 110546

Any help would be greatly appreciated. If you need any more information, please don't hesitate to ask.

  • OS: Windows 10
  • Photoshop Version: Photoshop-2021
  • Python Version: python-3.9

Additional Context:

I'm trying to write a script that will make contact sheets for me. My end goal is to make a program that will create composite images containing all images I throw in a folder. I'm aware of the ContactSheet II script included in photoshop, the problem I have with this is you need to run it folder by folder. I want automate the entire process. Select a folder containing sub folders that I need to make contact sheets of and just let it run. The amount of images in each file is a variable, so I need to generalize the size of the image, the gap between them and the amount of rows and columns, based on that.

how to set the unit for the new document

您好:
由于我后面所有的操作都是基于一些已经打印成A1尺寸的PDF或者A2、A3这类标准打印尺寸,所以我想在创建新文档的时候将单位设置设置成毫米。
image
但添加文档的时候没有设置单位的默认参数,输入的长宽都是以像素为单位。想请教一下我应该怎么设置新建文档的单位。
image
感谢回复!

Set resolution in TargaSaveOptions() gives an error

Hi,
I'm trying set resolution like this

from photoshop.enumerations import TargaBitsPerPixels
saveOptions = ps.TargaSaveOptions()
if (hasAlpha):
	saveOptions.resolution = TargaBitsPerPixels.THIRTYTWO
	saveOptions.alphaChannels = True
else:
	saveOptions.resolution = TargaBitsPerPixels.TWENTYFOUR
	saveOptions.alphaChannels = False

saveOptions.rleCompression = False

But it gives me an error

File "C:/Program Files/Adobe/Adobe Photoshop 2020/Presets/Scripts/QTE_Exporter/photoshop_actions.py", line 397, in CreateTgaSaveOptions
    saveOptions.resolution = TargaBitsPerPixels.THIRTYTWO
  File "C:\Program Files\Adobe\Adobe Photoshop 2020\Presets\Scripts\QTE_Exporter\venv\lib\site-packages\photoshop\save_options\tag.py", line 28, in resolution
    self.app.resolution = value
  File "C:\Program Files\Adobe\Adobe Photoshop 2020\Presets\Scripts\QTE_Exporter\venv\lib\site-packages\comtypes\client\lazybind.py", line 218, in __setattr__
    self._comobj._invoke(descr.memid, descr.invkind, 0, value)
  File "C:\Program Files\Adobe\Adobe Photoshop 2020\Presets\Scripts\QTE_Exporter\venv\lib\site-packages\comtypes\automation.py", line 729, in _invoke
    dp, var, None, argerr)
_ctypes.COMError: (-2147220278, None, (None, None, None, 0, None))

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.