-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy path12_export_selection_to_image.py
88 lines (74 loc) · 2.57 KB
/
12_export_selection_to_image.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
"""
Usage:
1. Select object(s) in InDesign document
2. Click "Export"
"""
import os
import wx # pip3 install wxPython
from appscript import *
indd = app("Adobe InDesign 2022")
desktop = os.path.expanduser("~/Desktop/") # default saveto = desktop
def selection_to_jpg(selection, saveto):
indd.JPEG_export_preference.properties_.set(
{
# image
k.JPEG_Quality: k.maximum, # k.low / k.medium / k.high / k.maximum
k.JPEG_Rendering_style: k.baseline_encoding, # k.progressive_encoding
k.export_resolution: 72,
k.jpeg_color_space: k.RGB, # k.RGB / k.CMYK / k.gray
# option
k.embed_color_profile: False,
k.anti_alias: True,
k.use_document_bleeds: False,
k.simulate_overprint: False,
}
)
indd.export(selection, format=k.JPG, to=saveto)
def selection_to_png(selection, saveto):
indd.PNG_export_preference.properties_.set(
{
# image
k.PNG_Quality: k.maximum, # k.low / k.medium / k.high / k.maximum
k.export_resolution: 72,
k.PNG_color_space: k.RGB, # k.RGB / k.gray
# option
k.transparent_background: True,
k.anti_alias: True,
k.use_document_bleeds: False,
k.simulate_overprint: False,
}
)
indd.export(selection, format=k.PNG_format, to=saveto)
class MyFrame (wx.Frame):
def __init__(self):
wx.Frame.__init__(self, None, id=-1, title="Export Image",
size=wx.Size(200, 150))
bSizer = wx.BoxSizer(wx.VERTICAL)
self.fmt = wx.RadioBox(self, -1, "Format", wx.DefaultPosition,
wx.DefaultSize, ["JPG", "PNG"], 1,
wx.RA_SPECIFY_ROWS)
self.fmt.SetSelection(0)
self.btn = wx.Button(self, -1, "Export")
bSizer.Add(self.fmt, 0, wx.ALL, 5)
bSizer.Add(self.btn, 0, wx.ALL, 5)
self.SetSizer(bSizer)
self.Layout()
self.Centre(wx.BOTH)
# Connect Events
self.btn.Bind(wx.EVT_BUTTON, self.export)
def export(self, event):
fmt = self.fmt.GetStringSelection()
if fmt == "JPG":
fn = selection_to_jpg
elif fmt == "PNG":
fn = selection_to_png
else:
raise Exception("Unknown format")
#
for i, x in enumerate(indd.selection()):
fn(x, f"{desktop}/_test_{i}.{fmt}")
print("Exported")
if __name__ == '__main__':
app = wx.App()
MyFrame().Show()
app.MainLoop()