diff options
Diffstat (limited to 'src/components')
| -rw-r--r-- | src/components/image.py | 21 | ||||
| -rw-r--r-- | src/components/image.ui | 64 |
2 files changed, 83 insertions, 2 deletions
diff --git a/src/components/image.py b/src/components/image.py index 4ccfc80..c9da137 100644 --- a/src/components/image.py +++ b/src/components/image.py @@ -1,4 +1,4 @@ -from PIL import Image, ImageDraw +from PIL import Image, ImageDraw, ImageEnhance from PyQt5 import QtGui, QtCore, QtWidgets import os @@ -20,7 +20,9 @@ class Component(Component): page.pushButton_image.clicked.connect(self.pickImage) page.spinBox_scale.valueChanged.connect(self.update) page.spinBox_rotate.valueChanged.connect(self.update) + page.spinBox_color.valueChanged.connect(self.update) page.checkBox_stretch.stateChanged.connect(self.update) + page.checkBox_mirror.stateChanged.connect(self.update) page.spinBox_x.valueChanged.connect(self.update) page.spinBox_y.valueChanged.connect(self.update) @@ -31,9 +33,11 @@ class Component(Component): self.imagePath = self.page.lineEdit_image.text() self.scale = self.page.spinBox_scale.value() self.rotate = self.page.spinBox_rotate.value() + self.color = self.page.spinBox_color.value() self.xPosition = self.page.spinBox_x.value() self.yPosition = self.page.spinBox_y.value() self.stretched = self.page.checkBox_stretch.isChecked() + self.mirror = self.page.checkBox_mirror.isChecked() self.parent.drawPreview() super().update() @@ -56,33 +60,48 @@ class Component(Component): frame = BlankFrame(width, height) if self.imagePath and os.path.exists(self.imagePath): image = Image.open(self.imagePath) + + # Modify image's appearance + if self.color != 100: + image = ImageEnhance.Color(image).enhance( + float(self.color / 100) + ) + if self.mirror: + image = image.transpose(Image.FLIP_LEFT_RIGHT) if self.stretched and image.size != (width, height): image = image.resize((width, height), Image.ANTIALIAS) if self.scale != 100: newHeight = int((image.height / 100) * self.scale) newWidth = int((image.width / 100) * self.scale) image = image.resize((newWidth, newHeight), Image.ANTIALIAS) + + # Paste image at correct position frame.paste(image, box=(self.xPosition, self.yPosition)) if self.rotate != 0: frame = frame.rotate(self.rotate) + return frame def loadPreset(self, pr, presetName=None): super().loadPreset(pr, presetName) self.page.lineEdit_image.setText(pr['image']) self.page.spinBox_scale.setValue(pr['scale']) + self.page.spinBox_color.setValue(pr['color']) self.page.spinBox_rotate.setValue(pr['rotate']) self.page.spinBox_x.setValue(pr['x']) self.page.spinBox_y.setValue(pr['y']) self.page.checkBox_stretch.setChecked(pr['stretched']) + self.page.checkBox_mirror.setChecked(pr['mirror']) def savePreset(self): return { 'preset': self.currentPreset, 'image': self.imagePath, 'scale': self.scale, + 'color': self.color, 'rotate': self.rotate, 'stretched': self.stretched, + 'mirror': self.mirror, 'x': self.xPosition, 'y': self.yPosition, } diff --git a/src/components/image.ui b/src/components/image.ui index 33488f8..e549ed0 100644 --- a/src/components/image.ui +++ b/src/components/image.ui @@ -209,9 +209,16 @@ </spacer> </item> <item> + <widget class="QCheckBox" name="checkBox_mirror"> + <property name="text"> + <string>Mirror</string> + </property> + </widget> + </item> + <item> <widget class="QLabel" name="label_2"> <property name="text"> - <string>Rotation</string> + <string>Rotate</string> </property> <property name="alignment"> <set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set> @@ -291,6 +298,61 @@ </layout> </item> <item> + <layout class="QHBoxLayout" name="horizontalLayout_2"> + <item> + <spacer name="horizontalSpacer_2"> + <property name="orientation"> + <enum>Qt::Horizontal</enum> + </property> + <property name="sizeHint" stdset="0"> + <size> + <width>40</width> + <height>20</height> + </size> + </property> + </spacer> + </item> + <item> + <widget class="QLabel" name="label_3"> + <property name="sizePolicy"> + <sizepolicy hsizetype="Fixed" vsizetype="Preferred"> + <horstretch>0</horstretch> + <verstretch>0</verstretch> + </sizepolicy> + </property> + <property name="text"> + <string>Color</string> + </property> + <property name="alignment"> + <set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set> + </property> + </widget> + </item> + <item> + <widget class="QSpinBox" name="spinBox_color"> + <property name="buttonSymbols"> + <enum>QAbstractSpinBox::UpDownArrows</enum> + </property> + <property name="suffix"> + <string>%</string> + </property> + <property name="minimum"> + <number>0</number> + </property> + <property name="maximum"> + <number>999</number> + </property> + <property name="singleStep"> + <number>1</number> + </property> + <property name="value"> + <number>100</number> + </property> + </widget> + </item> + </layout> + </item> + <item> <spacer name="verticalSpacer"> <property name="orientation"> <enum>Qt::Vertical</enum> |
