cinaeco 5 rokov pred
commit
c03570b82e

+ 8 - 0
bleed_generator.desktop

@@ -0,0 +1,8 @@
+[Desktop Entry]
+Type=Service
+ServiceTypes=Krita/PythonPlugin
+X-KDE-Library=bleed_generator
+X-Python-2-Compatible=false
+X-Krita-Manual=Manual.html
+Name=Bleed Generator
+Comment=Creates bleed on image layers by cloning the pixels on the edges.

+ 24 - 0
bleed_generator/Manual.html

@@ -0,0 +1,24 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!DOCTYPE html>
+
+<html xmlns="http://www.w3.org/1999/xhtml">
+<head><title>Bleed Generator Documentation</title>
+</head>
+<body>
+<h3>Bleed Generator Documentation</h3>
+
+This extension creates artificial "bleed" on the edges of a given layer, by
+simply cloning the edges outward. This is mainly used for preparing images for
+double sided printing, such as print and play card games.
+
+Defaults to 2mm bleed on all sides, which is sufficient leeway for most
+printers.
+
+<h3>Usage</h3>
+
+Run the generator while having a paint layer selected. Bleed amount can be
+specified in millimetres, inches and pixels. "Offset" allows the use of pixel
+lines other than the edge. A "-1" offset means bleed will be copied from 1 line
+just inside the edge, "-2" means 2 lines in, etc.
+</body>
+</html>

+ 3 - 0
bleed_generator/__init__.py

@@ -0,0 +1,3 @@
+from .bleed_generator_extension import BleedGenerator
+
+Krita.instance().addExtension(BleedGenerator(Krita.instance()))

BIN
bleed_generator/__pycache__/__init__.cpython-38.pyc


BIN
bleed_generator/__pycache__/bleed_generator_extension.cpython-38.pyc


+ 154 - 0
bleed_generator/bleed_generator_extension.py

@@ -0,0 +1,154 @@
+from krita import *
+from PyQt5.QtWidgets import QDialog, QVBoxLayout, QHBoxLayout, QLabel, QLineEdit, QComboBox, QCheckBox, QPushButton
+from PyQt5.QtCore import *
+
+class BleedGenerator(Extension):
+
+    def __init__(self, parent):
+        super().__init__(parent)
+
+    # Krita.instance() exists, so do any setup work
+    def setup(self):
+        pass
+
+    # called after setup(self)
+    def createActions(self, window):
+        # Create menu item in Tools > Scripts.
+        action = window.createAction("bleedgen", "Bleed Generator")
+        action.triggered.connect(self.bleed_generator)
+
+    def bleed_generator(self):
+        # Get the current selected layer, called a 'node'
+        self.doc = Krita.instance().activeDocument()
+        self.layer = self.doc.activeNode()
+
+        # Create dialog.
+        newDialog = QDialog()
+        newDialog.setWindowTitle("Bleed Generator!")
+
+        desc = QLabel('Adds bleed to the active paint layer')
+        desc.setAlignment(Qt.AlignCenter)
+
+        # Count and unit inputs. Default to 2mm.
+        self.countInput = QLineEdit('2')
+        self.unitInput = QComboBox()
+        self.unitInput.addItems( ['mm', 'inch', 'px'] )
+        self.unitIndex = 0 # track current unit.
+        self.offsetInput = QLineEdit('0')
+
+        # Side selection
+        self.topCheck = QCheckBox('Top')
+        self.topCheck.setChecked(True)
+        self.botCheck = QCheckBox('Bottom')
+        self.botCheck.setChecked(True)
+        self.leftCheck = QCheckBox('Left')
+        self.leftCheck.setChecked(True)
+        self.rightCheck = QCheckBox('Right')
+        self.rightCheck.setChecked(True)
+
+        # Button!
+        goButton = QPushButton("Add Bleed")
+        goButton.setIcon( Krita.instance().icon('animation_play') )
+
+        # create layouts
+        row0 = QHBoxLayout()
+        row1 = QHBoxLayout()
+        row2 = QHBoxLayout()
+        row3 = QHBoxLayout()
+        row0.addWidget(desc)
+        row1.addWidget(QLabel('How much bleed:'))
+        row1.addWidget(self.countInput)
+        row1.addWidget(self.unitInput)
+        row1.addWidget(QLabel('Offset (0 = use edge):'))
+        row1.addWidget(self.offsetInput)
+        row2.addWidget(QLabel('Sides to bleed:'))
+        row2.addWidget(self.topCheck)
+        row2.addWidget(self.botCheck)
+        row2.addWidget(self.leftCheck)
+        row2.addWidget(self.rightCheck)
+
+        if self.layer.type() != 'paintlayer':
+            desc.setText('Please select a paint layer!')
+        else:
+            row3.addWidget(goButton)
+
+        layoutMain = QVBoxLayout()
+        layoutMain.addLayout(row0)
+        layoutMain.addLayout(row1)
+        layoutMain.addLayout(row2)
+        layoutMain.addLayout(row3)
+        newDialog.setLayout(layoutMain)
+
+        # hook up the actions.
+        goButton.clicked.connect( self.generateBleed )
+        # self.unitInput.currentIndexChanged.connect( self.convertCount )
+
+        # show the dialog.
+        newDialog.exec_()
+
+
+    ##########
+    # Slots
+    ##########
+
+    # Actually generates the bleed!
+    def generateBleed(self, e):
+
+        # Calculate how many lines of pixels to copy.
+        unit = self.unitInput.currentIndex()
+        count = float(self.countInput.text())
+        ppi = self.doc.resolution()
+        if unit == 0: # mm
+            count = count * (ppi / 24.5)
+        if unit == 1: # inch
+            count = count * ppi
+        offset = round(float(self.offsetInput.text()))
+        count = round(count) - offset
+        print("Pixel bleed amount: ", count)
+        print("Edge offset: ", offset)
+
+        # Copy lines for selected sides.
+        if self.topCheck.checkState():
+            bds = self.layer.bounds()
+            xpos = bds.left()
+            ypos = bds.top() - offset
+            len = bds.width()
+            bleedline = self.layer.pixelData(xpos, ypos, len, 1)
+            for c in range(1, count+1):
+                self.layer.setPixelData(bleedline, xpos, (ypos - c), len, 1)
+            print("Top lines cloned: ", count)
+        if self.botCheck.checkState():
+            bds = self.layer.bounds()
+            xpos = bds.left()
+            ypos = bds.bottom() + offset
+            len = bds.width()
+            bleedline = self.layer.pixelData(xpos, ypos, len, 1)
+            for c in range(1, count+1):
+                self.layer.setPixelData(bleedline, xpos, (ypos + c), len, 1)
+            print("Bottom lines cloned: ", count)
+        if self.leftCheck.checkState():
+            bds = self.layer.bounds()
+            xpos = bds.left() - offset
+            ypos = bds.top()
+            len = bds.height()
+            bleedline = self.layer.pixelData(xpos, ypos, 1, len)
+            for c in range(1, count+1):
+                self.layer.setPixelData(bleedline, (xpos - c), ypos, 1, len)
+            print("Left lines cloned: ", count)
+        if self.rightCheck.checkState():
+            bds = self.layer.bounds()
+            xpos = bds.right() + offset
+            ypos = bds.top()
+            len = bds.height()
+            bleedline = self.layer.pixelData(xpos, ypos, 1, len)
+            for c in range(1, count+1):
+                self.layer.setPixelData(bleedline, (xpos + c), ypos, 1, len)
+            print("Right lines cloned: ", count)
+
+
+        self.doc.refreshProjection()
+
+    # Convert count input values to relevant units
+    def convertCount():
+        unitIndex = unitInput.currentIndex()
+        print("Updated unit index: ", unitIndex)

+ 8 - 0
box_generator.desktop

@@ -0,0 +1,8 @@
+[Desktop Entry]
+Type=Service
+ServiceTypes=Krita/PythonPlugin
+X-KDE-Library=box_generator
+X-Python-2-Compatible=false
+X-Krita-Manual=Manual.html
+Name=Box Generator
+Comment=Creates outlines for foldable boxes according to a specified internal size.

+ 23 - 0
box_generator/Manual.html

@@ -0,0 +1,23 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!DOCTYPE html>
+
+<html xmlns="http://www.w3.org/1999/xhtml">
+<!--BBD's Krita Script Starter, Feb 2018 -->
+<head><title>Extension Template Documentation</title>
+</head>
+<body>
+<h3>Box Generator documentation</h3>
+
+This creates artificial "bleed" on the edges of a given layer, but simply
+cloning the edges outward. This is mainly used for printing double sided print
+and play card games. Defaults to 2mm bleed on all sides.
+
+<h3>Usage</h3>
+
+Run the generator after the desired paint layer is selected. Bleed amount can be
+specified in millimetres, inches and pixels. "Offset" allows the use of pixel
+lines other than the edge. A -1 offset means bleed will be copied from 1 line
+just inside the edge, -2 means 2 lines in, etc.
+
+</body>
+</html>

+ 3 - 0
box_generator/__init__.py

@@ -0,0 +1,3 @@
+from .box_generator_extension import BoxGenerator
+
+Krita.instance().addExtension(BoxGenerator(Krita.instance()))

BIN
box_generator/__pycache__/__init__.cpython-38.pyc


BIN
box_generator/__pycache__/bleed_generator_extension.cpython-38.pyc


BIN
box_generator/__pycache__/box_generator_extension.cpython-38.pyc


+ 145 - 0
box_generator/box_generator_extension.py

@@ -0,0 +1,145 @@
+from krita import *
+from PyQt5.QtWidgets import QDialog, QVBoxLayout, QHBoxLayout, QLabel, QLineEdit, QComboBox, QCheckBox, QPushButton
+from PyQt5.QtCore import *
+
+class BoxGenerator(Extension):
+
+    def __init__(self, parent):
+        super().__init__(parent)
+
+    # Krita.instance() exists, so do any setup work
+    def setup(self):
+        pass
+
+    # called after setup(self)
+    def createActions(self, window):
+        # Create menu item in Tools > Scripts.
+        action = window.createAction("boxgen", "Box Generator")
+        action.triggered.connect(self.box_generator)
+
+    def box_generator(self):
+        # Get the current selected layer, called a 'node'
+        self.doc = Krita.instance().activeDocument()
+
+        if not self.doc:
+            # Create and show a new document (A4 300ppi).
+            self.doc = Krita.instance().createDocument(3508, 2480, "", "RGBA", "U8", "", 300.0)
+            Krita.instance().activeWindow().addView(self.doc)
+
+        # Dialog creation.
+        newDialog = QDialog()
+        newDialog.setWindowTitle("Box Generator")
+
+        # Description row.
+        desc = QLabel('Creates outlines for a foldable box with lid.')
+        desc.setAlignment(Qt.AlignCenter)
+        row0 = QHBoxLayout()
+        row0.addWidget(desc)
+
+        # Dimension row.
+        self.lengthInput = QLineEdit('95')
+        self.widthInput = QLineEdit('70')
+        self.heightInput = QLineEdit('20')
+        self.unitInput = QComboBox()
+        self.unitInput.addItems( ['mm', 'inch', 'px'] )
+        row1 = QHBoxLayout()
+        row1.addWidget(QLabel('Dimensions: L:'))
+        row1.addWidget(self.lengthInput)
+        row1.addWidget(QLabel(' x W:'))
+        row1.addWidget(self.widthInput)
+        row1.addWidget(QLabel(' x H:'))
+        row1.addWidget(self.heightInput)
+        row1.addWidget(self.unitInput)
+
+        # Decision row.
+        self.flapCheck = QCheckBox('Flap')
+        self.flapCheck.setChecked(True)
+        row2 = QHBoxLayout()
+        row2.addWidget(self.flapCheck)
+
+        # Do It row.
+        goButton = QPushButton("Create Box")
+        goButton.setIcon( Krita.instance().icon('animation_play') )
+        row3 = QHBoxLayout()
+        row3.addWidget(goButton)
+
+        layoutMain = QVBoxLayout()
+        layoutMain.addLayout(row0)
+        layoutMain.addLayout(row1)
+        layoutMain.addLayout(row2)
+        layoutMain.addLayout(row3)
+        newDialog.setLayout(layoutMain)
+
+        # hook up the actions.
+        # goButton.clicked.connect( self.generateBox )
+        # self.unitInput.currentIndexChanged.connect( self.convertCount )
+
+        # show the dialog.
+        newDialog.exec_()
+
+
+    ##########
+    # Slots
+    ##########
+
+    # Actually generates the box!
+    def generateBox(self, e):
+
+        # Calculate how many lines of pixels to copy.
+        unit = self.unitInput.currentIndex()
+        count = float(self.countInput.text())
+        ppi = self.doc.resolution()
+        if unit == 0: # mm
+            count = count * (ppi / 24.5)
+        if unit == 1: # inch
+            count = count * ppi
+        offset = round(float(self.offsetInput.text()))
+        count = round(count) - offset
+        print("Pixel bleed amount: ", count)
+        print("Edge offset: ", offset)
+
+        # Copy lines for selected sides.
+        if self.topCheck.checkState():
+            bds = self.layer.bounds()
+            xpos = bds.left()
+            ypos = bds.top() - offset
+            len = bds.width()
+            bleedline = self.layer.pixelData(xpos, ypos, len, 1)
+            for c in range(1, count+1):
+                self.layer.setPixelData(bleedline, xpos, (ypos - c), len, 1)
+            print("Top lines cloned: ", count)
+        if self.botCheck.checkState():
+            bds = self.layer.bounds()
+            xpos = bds.left()
+            ypos = bds.bottom() + offset
+            len = bds.width()
+            bleedline = self.layer.pixelData(xpos, ypos, len, 1)
+            for c in range(1, count+1):
+                self.layer.setPixelData(bleedline, xpos, (ypos + c), len, 1)
+            print("Bottom lines cloned: ", count)
+        if self.leftCheck.checkState():
+            bds = self.layer.bounds()
+            xpos = bds.left() - offset
+            ypos = bds.top()
+            len = bds.height()
+            bleedline = self.layer.pixelData(xpos, ypos, 1, len)
+            for c in range(1, count+1):
+                self.layer.setPixelData(bleedline, (xpos - c), ypos, 1, len)
+            print("Left lines cloned: ", count)
+        if self.rightCheck.checkState():
+            bds = self.layer.bounds()
+            xpos = bds.right() + offset
+            ypos = bds.top()
+            len = bds.height()
+            bleedline = self.layer.pixelData(xpos, ypos, 1, len)
+            for c in range(1, count+1):
+                self.layer.setPixelData(bleedline, (xpos + c), ypos, 1, len)
+            print("Right lines cloned: ", count)
+
+
+        self.doc.refreshProjection()
+
+    # Convert count input values to relevant units
+    def convertCount():
+        unitIndex = unitInput.currentIndex()
+        print("Updated unit index: ", unitIndex)

+ 8 - 0
page_resizer.desktop

@@ -0,0 +1,8 @@
+[Desktop Entry]
+Type=Service
+ServiceTypes=Krita/PythonPlugin
+X-KDE-Library=page_resizer
+X-Python-2-Compatible=false
+X-Krita-Manual=Manual.html
+Name=Page Resizer
+Comment=Resizes documents (defaults to A4).

+ 14 - 0
page_resizer/Manual.html

@@ -0,0 +1,14 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!DOCTYPE html>
+
+<html xmlns="http://www.w3.org/1999/xhtml">
+<head><title>Page Resizer</title>
+</head>
+<body>
+<h3>Page Resizer Documentation</h3>
+
+Resizes images to a particular size (defaults to A4). All layers are centered
+and filled to the new canvas space.
+
+</body>
+</html>

+ 3 - 0
page_resizer/__init__.py

@@ -0,0 +1,3 @@
+from .page_resizer import PageResizer
+
+Krita.instance().addExtension(PageResizer(Krita.instance()))

BIN
page_resizer/__pycache__/__init__.cpython-38.pyc


BIN
page_resizer/__pycache__/bleed_generator_extension.cpython-38.pyc


BIN
page_resizer/__pycache__/letter_to_a4_resizer.cpython-38.pyc


BIN
page_resizer/__pycache__/page_resizer.cpython-38.pyc


+ 153 - 0
page_resizer/page_resizer.py

@@ -0,0 +1,153 @@
+from krita import *
+from PyQt5.QtWidgets import QDialog, QVBoxLayout, QHBoxLayout, QLabel, QLineEdit, QComboBox, QCheckBox, QPushButton
+from PyQt5.QtCore import *
+
+class PageResizer(Extension):
+
+    def __init__(self, parent):
+        super().__init__(parent)
+
+    # Krita.instance() exists, so do any setup work
+    def setup(self):
+        pass
+
+    # called after setup(self)
+    def createActions(self, window):
+        # Create menu item in Tools > Scripts.
+        action = window.createAction("PageResizer", "Page Resizer")
+        action.triggered.connect(self.resizer)
+
+    def resizer(self):
+        # Get the current document.
+        self.doc = Krita.instance().activeDocument()
+
+        # Create dialog.
+        newDialog = QDialog()
+        newDialog.setWindowTitle("Bleed Generator!")
+
+        desc = QLabel('Adds bleed to the active paint layer')
+        desc.setAlignment(Qt.AlignCenter)
+
+        # Count and unit inputs. Default to 2mm.
+        self.countInput = QLineEdit('2')
+        self.unitInput = QComboBox()
+        self.unitInput.addItems( ['mm', 'inch', 'px'] )
+        self.unitIndex = 0 # track current unit.
+        self.offsetInput = QLineEdit('0')
+
+        # Side selection
+        self.topCheck = QCheckBox('Top')
+        self.topCheck.setChecked(True)
+        self.botCheck = QCheckBox('Bottom')
+        self.botCheck.setChecked(True)
+        self.leftCheck = QCheckBox('Left')
+        self.leftCheck.setChecked(True)
+        self.rightCheck = QCheckBox('Right')
+        self.rightCheck.setChecked(True)
+
+        # Button!
+        goButton = QPushButton("Add Bleed")
+        goButton.setIcon( Krita.instance().icon('animation_play') )
+
+        # create layouts
+        row0 = QHBoxLayout()
+        row1 = QHBoxLayout()
+        row2 = QHBoxLayout()
+        row3 = QHBoxLayout()
+        row0.addWidget(desc)
+        row1.addWidget(QLabel('How much bleed:'))
+        row1.addWidget(self.countInput)
+        row1.addWidget(self.unitInput)
+        row1.addWidget(QLabel('Offset (0 = use edge):'))
+        row1.addWidget(self.offsetInput)
+        row2.addWidget(QLabel('Sides to bleed:'))
+        row2.addWidget(self.topCheck)
+        row2.addWidget(self.botCheck)
+        row2.addWidget(self.leftCheck)
+        row2.addWidget(self.rightCheck)
+
+        if self.layer.type() != 'paintlayer':
+            desc.setText('Please select a paint layer!')
+        else:
+            row3.addWidget(goButton)
+
+        layoutMain = QVBoxLayout()
+        layoutMain.addLayout(row0)
+        layoutMain.addLayout(row1)
+        layoutMain.addLayout(row2)
+        layoutMain.addLayout(row3)
+        newDialog.setLayout(layoutMain)
+
+        # hook up the actions.
+        goButton.clicked.connect( self.generateBleed )
+        # self.unitInput.currentIndexChanged.connect( self.convertCount )
+
+        # show the dialog.
+        newDialog.exec_()
+
+
+    ##########
+    # Slots
+    ##########
+
+    # Actually generates the bleed!
+    def generateBleed(self, e):
+
+        # Calculate how many lines of pixels to copy.
+        unit = self.unitInput.currentIndex()
+        count = float(self.countInput.text())
+        ppi = self.doc.resolution()
+        if unit == 0: # mm
+            count = count * (ppi / 24.5)
+        if unit == 1: # inch
+            count = count * ppi
+        offset = round(float(self.offsetInput.text()))
+        count = round(count) - offset
+        print("Pixel bleed amount: ", count)
+        print("Edge offset: ", offset)
+
+        # Copy lines for selected sides.
+        if self.topCheck.checkState():
+            bds = self.layer.bounds()
+            xpos = bds.left()
+            ypos = bds.top() - offset
+            len = bds.width()
+            bleedline = self.layer.pixelData(xpos, ypos, len, 1)
+            for c in range(1, count+1):
+                self.layer.setPixelData(bleedline, xpos, (ypos - c), len, 1)
+            print("Top lines cloned: ", count)
+        if self.botCheck.checkState():
+            bds = self.layer.bounds()
+            xpos = bds.left()
+            ypos = bds.bottom() + offset
+            len = bds.width()
+            bleedline = self.layer.pixelData(xpos, ypos, len, 1)
+            for c in range(1, count+1):
+                self.layer.setPixelData(bleedline, xpos, (ypos + c), len, 1)
+            print("Bottom lines cloned: ", count)
+        if self.leftCheck.checkState():
+            bds = self.layer.bounds()
+            xpos = bds.left() - offset
+            ypos = bds.top()
+            len = bds.height()
+            bleedline = self.layer.pixelData(xpos, ypos, 1, len)
+            for c in range(1, count+1):
+                self.layer.setPixelData(bleedline, (xpos - c), ypos, 1, len)
+            print("Left lines cloned: ", count)
+        if self.rightCheck.checkState():
+            bds = self.layer.bounds()
+            xpos = bds.right() + offset
+            ypos = bds.top()
+            len = bds.height()
+            bleedline = self.layer.pixelData(xpos, ypos, 1, len)
+            for c in range(1, count+1):
+                self.layer.setPixelData(bleedline, (xpos + c), ypos, 1, len)
+            print("Right lines cloned: ", count)
+
+
+        self.doc.refreshProjection()
+
+    # Convert count input values to relevant units
+    def convertCount():
+        unitIndex = unitInput.currentIndex()
+        print("Updated unit index: ", unitIndex)