Skip to content

Commit ed73783

Browse files
Investigamerloonghao
authored andcommitted
feat(png.py): Add optional args to PNGSaveOptions
Additionally added stronger type hinting, matching types accurately to Adobe scripting documentation Signed-off-by: MrTeferi <freethoughtleft@gmail.com>
1 parent 8ec9687 commit ed73783

File tree

2 files changed

+24
-17
lines changed

2 files changed

+24
-17
lines changed

.pre-commit-config.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ repos:
1616
- additional_dependencies:
1717
- flake8-typing-imports==1.5.0
1818
id: flake8
19-
repo: https://gitlab.com/pycqa/flake8
19+
repo: https://github.com/pycqa/flake8
2020
rev: 3.7.9
2121
- hooks:
2222
- id: autopep8

photoshop/api/save_options/png.py

Lines changed: 23 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,21 @@
11
# Import local modules
22
from photoshop.api._core import Photoshop
3+
from photoshop.api.enumerations import ColorReductionType
4+
from photoshop.api.enumerations import DitherType
35

46

57
class ExportOptionsSaveForWeb(Photoshop):
68
"""Options for exporting Save For Web files."""
79

8-
object_name = "ExportOptionsSaveForWeb"
10+
object_name = 'ExportOptionsSaveForWeb'
911

1012
def __init__(self):
1113
super().__init__()
1214
self.format = 13 # PNG
1315
self.PNG8 = False # Sets it to PNG-24 bit
1416

1517
@property
16-
def PNG8(self):
18+
def PNG8(self) -> bool:
1719
"""If true, uses 8 bits. If false, uses 24 bits. Valid only when ‘format’ = PNG."""
1820
return self.app.PNG8
1921

@@ -22,41 +24,44 @@ def PNG8(self, value: bool):
2224
self.app.PNG8 = value
2325

2426
@property
25-
def blur(self):
27+
def blur(self) -> float:
28+
"""Applies blur to the image to reduce artifacts."""
2629
return self.app.blur
2730

2831
@blur.setter
29-
def blur(self, value):
32+
def blur(self, value: float):
3033
self.app.blur = value
3134

3235
@property
33-
def colorReduction(self):
36+
def colorReduction(self) -> ColorReductionType:
37+
"""The color reduction algorithm."""
3438
return self.app.colorReduction
3539

3640
@colorReduction.setter
37-
def colorReduction(self, value):
41+
def colorReduction(self, value: ColorReductionType):
3842
self.app.colorReduction = value
3943

4044
@property
41-
def colors(self):
45+
def colors(self) -> int:
4246
"""The number of colors in the palette."""
4347
return self.app.colors
4448

4549
@colors.setter
46-
def colors(self, value):
47-
"""The number of colors in the palette."""
50+
def colors(self, value: int):
4851
self.app.colors = value
4952

5053
@property
51-
def dither(self):
54+
def dither(self) -> DitherType:
55+
"""The type of dither to use."""
5256
return self.app.dither
5357

5458
@dither.setter
55-
def dither(self, value):
59+
def dither(self, value: DitherType):
5660
self.app.dither = value
5761

5862
@property
59-
def quality(self):
63+
def quality(self) -> int:
64+
"""The quality of the output image, from 0 to 100."""
6065
return self.app.quality
6166

6267
@quality.setter
@@ -65,12 +70,14 @@ def quality(self, value: int):
6570

6671

6772
class PNGSaveOptions(Photoshop):
68-
object_name = "PNGSaveOptions"
73+
"""Options for saving file as PNG."""
6974

70-
def __init__(self):
75+
object_name = 'PNGSaveOptions'
76+
77+
def __init__(self, interlaced: bool = False, compression: int = 6):
7178
super().__init__()
72-
self.interlaced = False
73-
self.compression = 6
79+
self.interlaced = interlaced
80+
self.compression = compression
7481

7582
@property
7683
def interlaced(self) -> bool:

0 commit comments

Comments
 (0)