Changeset View
Changeset View
Standalone View
Standalone View
plugins/python/example_scripts/resize_to_all_layers.py
1 | ''' | 1 | # This script is licensed CC 0 1.0, so that you can learn from it. | ||
---|---|---|---|---|---|
2 | This script is licensed CC 0 1.0, so that you can learn from it. | | |||
3 | 2 | | |||
4 | ------ CC 0 1.0 --------------- | 3 | # ------ CC 0 1.0 --------------- | ||
5 | 4 | | |||
6 | The person who associated a work with this deed has dedicated the work to the public domain by waiving all of his or her rights to the work worldwide under copyright law, including all related and neighboring rights, to the extent allowed by law. | 5 | # The person who associated a work with this deed has dedicated the | ||
6 | # work to the public domain by waiving all of his or her rights to the | ||||
7 | # work worldwide under copyright law, including all related and | ||||
8 | # neighboring rights, to the extent allowed by law. | ||||
7 | 9 | | |||
8 | You can copy, modify, distribute and perform the work, even for commercial purposes, all without asking permission. | 10 | # You can copy, modify, distribute and perform the work, even for | ||
11 | # commercial purposes, all without asking permission. | ||||
12 | | ||||
13 | # https://creativecommons.org/publicdomain/zero/1.0/legalcode | ||||
14 | | ||||
15 | """ | ||||
16 | This script will iterate over all toplevel nodes, create | ||||
17 | keeping track of the layer boundaries and then resize | ||||
18 | the image to the unity of all boundaries. | ||||
19 | """ | ||||
20 | | ||||
21 | from krita import Krita | ||||
22 | from PyQt5.QtCore import QRect | ||||
9 | 23 | | |||
10 | https://creativecommons.org/publicdomain/zero/1.0/legalcode | | |||
11 | ''' | | |||
12 | # | | |||
13 | # This script will iterate over all toplevel nodes, create | | |||
14 | # keeping track of the layer boundaries and then resize | | |||
15 | # the image to the unity of all boundaries. | | |||
16 | # | | |||
17 | from krita import * | | |||
18 | d = Krita.instance().activeDocument() | 24 | d = Krita.instance().activeDocument() | ||
19 | w = d.width() | 25 | w = d.width() | ||
20 | h = d.height() | 26 | h = d.height() | ||
21 | x = d.xOffset() | 27 | x = d.xOffset() | ||
22 | y = d.yOffset() | 28 | y = d.yOffset() | ||
23 | 29 | | |||
24 | print(x, y, w, h) | 30 | print(x, y, w, h) | ||
25 | r = QRect(x, y, w, h) | 31 | r = QRect(x, y, w, h) | ||
26 | print(r) | 32 | print(r) | ||
27 | for n in d.topLevelNodes(): | 33 | for n in d.topLevelNodes(): | ||
28 | print (n, n.bounds()) | 34 | print(n, n.bounds()) | ||
29 | b = n.bounds() | 35 | b = n.bounds() | ||
30 | r = r.united(b) | 36 | r = r.united(b) | ||
31 | 37 | | |||
32 | print (r) | 38 | print(r) | ||
33 | 39 | | |||
34 | d.resizeImage(r.x(), r.y(), r.width(), r.height()) | 40 | d.resizeImage(r.x(), r.y(), r.width(), r.height()) |