aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDH42017-05-27 03:06:17 -0500
committerDH42017-05-27 03:06:17 -0500
commitf2329e93660780fc261abdbbd9d43884fdcaf722 (patch)
tree864b0fb72acb042d116d9b0e4064ad578c88b6b3
parenteaee0ab233709c18324dbb25f38b59c95c447e3c (diff)
Added automatic scaling of Image and bars. Set title x/y position, and font size based on scale.
-rw-r--r--core.py27
-rw-r--r--main.py10
-rw-r--r--preview_thread.py1
-rw-r--r--video_thread.py22
4 files changed, 35 insertions, 25 deletions
diff --git a/core.py b/core.py
index 900a98f..d360ca6 100644
--- a/core.py
+++ b/core.py
@@ -45,7 +45,7 @@ class Core():
def drawBaseImage(self, backgroundFile, titleText, titleFont, fontSize, alignment,\
xOffset, yOffset, textColor, visColor):
if backgroundFile == '':
- im = Image.new("RGB", (1280, 720), "black")
+ im = Image.new("RGB", (int(self.settings.value('outputWidth')), int(self.settings.value('outputHeight'))), "black")
else:
im = Image.open(backgroundFile)
@@ -53,8 +53,8 @@ class Core():
self.lastBackgroundImage = backgroundFile
# resize if necessary
- if not im.size == (1280, 720):
- im = im.resize((1280, 720), Image.ANTIALIAS)
+ if not im.size == (int(self.settings.value('outputWidth')), int(self.settings.value('outputHeight'))):
+ im = im.resize((int(self.settings.value('outputWidth')), int(self.settings.value('outputHeight'))), Image.ANTIALIAS)
self._image = ImageQt(im)
@@ -89,21 +89,32 @@ class Core():
def drawBars(self, spectrum, image, color):
- imTop = Image.new("RGBA", (1280, 360))
+ width = int(self.settings.value('outputWidth'))
+ height = int(int(self.settings.value('outputHeight'))/2)
+
+ imTop = Image.new("RGBA", (width, height))
draw = ImageDraw.Draw(imTop)
r, g, b = color
color2 = (r, g, b, 50)
+
+ vH = height-height/8
+ bF = int(self.settings.value('outputWidth')) / 64
+ bH = bF / 2
+ bQ = bF / 4
+
+ bP = int(self.settings.value('outputHeight')) / 800
+
for j in range(0, 63):
- draw.rectangle((10 + j * 20, 325, 10 + j * 20 + 20, 325 - spectrum[j * 4] * 1 - 10), fill=color2)
- draw.rectangle((15 + j * 20, 320, 15 + j * 20 + 10, 320 - spectrum[j * 4] * 1), fill=color)
+ draw.rectangle((bH + j * bF, vH, bH + j * bF + bF, vH + bQ - spectrum[j * 4] * bP - bH), fill=color2)
+ draw.rectangle((bH + bQ + j * bF, vH - bQ , bH + bQ + j * bF + bH, vH - spectrum[j * 4] * bP), fill=color)
imBottom = imTop.transpose(Image.FLIP_TOP_BOTTOM)
- im = Image.new("RGB", (1280, 720), "black")
+ im = Image.new("RGB", (int(self.settings.value('outputWidth')), int(self.settings.value('outputHeight'))), "black")
im.paste(image, (0, 0))
im.paste(imTop, (0, 0), mask=imTop)
- im.paste(imBottom, (0, 360), mask=imBottom)
+ im.paste(imBottom, (0, int(vH+bF*.7)), mask=imBottom)
return im
diff --git a/main.py b/main.py
index 3915c71..bfa8fbd 100644
--- a/main.py
+++ b/main.py
@@ -107,8 +107,6 @@ class Command(QtCore.QObject):
self.settings.setValue("textColor", '%s,%s,%s' % self.textColor)
sys.exit(0)
-
-
class Main(QtCore.QObject):
newTask = QtCore.pyqtSignal(str, str, QFont, int, int, int, int, tuple, tuple)
@@ -122,7 +120,6 @@ class Main(QtCore.QObject):
self.window = window
self.core = core.Core()
self.settings = QSettings('settings.ini', QSettings.IniFormat)
-
LoadDefaultSettings(self)
# load colors as tuples from a comma-separated string
@@ -168,9 +165,10 @@ class Main(QtCore.QObject):
window.alignmentComboBox.addItem("Left")
window.alignmentComboBox.addItem("Middle")
window.alignmentComboBox.addItem("Right")
- window.fontsizeSpinBox.setValue(35)
- window.textXSpinBox.setValue(70)
- window.textYSpinBox.setValue(375)
+ window.alignmentComboBox.setCurrentIndex(1)
+ window.fontsizeSpinBox.setValue(int(int(self.settings.value("outputHeight")) / 16 ))
+ window.textXSpinBox.setValue(int(int(self.settings.value('outputWidth'))/2))
+ window.textYSpinBox.setValue(int(int(self.settings.value('outputHeight'))/2))
window.lineEdit_textColor.setText('%s,%s,%s' % self.textColor)
window.lineEdit_visColor.setText('%s,%s,%s' % self.visColor)
window.pushButton_textColor.clicked.connect(lambda: self.pickColor('text'))
diff --git a/preview_thread.py b/preview_thread.py
index 041d39e..8195712 100644
--- a/preview_thread.py
+++ b/preview_thread.py
@@ -17,6 +17,7 @@ class Worker(QtCore.QObject):
parent.processTask.connect(self.process)
self.core = core.Core()
self.queue = queue
+ self.core.settings = parent.settings
@pyqtSlot(str, str, QtGui.QFont, int, int, int, int, tuple, tuple)
diff --git a/video_thread.py b/video_thread.py
index fe1f6f6..5b9a896 100644
--- a/video_thread.py
+++ b/video_thread.py
@@ -15,10 +15,10 @@ class Worker(QtCore.QObject):
def __init__(self, parent=None):
QtCore.QObject.__init__(self)
- self.settings = parent.settings
- parent.videoTask.connect(self.createVideo)
self.core = core.Core()
-
+ self.core.settings = parent.settings
+ parent.videoTask.connect(self.createVideo)
+
@pyqtSlot(str, str, QtGui.QFont, int, int, int, int, tuple, tuple, str, str)
def createVideo(self, backgroundImage, titleText, titleFont, fontSize, alignment,\
@@ -53,7 +53,7 @@ class Worker(QtCore.QObject):
# test if user has libfdk_aac
encoders = sp.check_output(self.core.FFMPEG_BIN + " -encoders -hide_banner", shell=True)
- acodec = self.settings.value('outputAudioCodec')
+ acodec = self.core.settings.value('outputAudioCodec')
if b'libfdk_aac' in encoders and acodec == 'aac':
acodec = 'libfdk_aac'
@@ -62,18 +62,18 @@ class Worker(QtCore.QObject):
'-y', # (optional) means overwrite the output file if it already exists.
'-f', 'rawvideo',
'-vcodec', 'rawvideo',
- '-s', self.settings.value('outputWidth')+'x'+self.settings.value('outputHeight'), # size of one frame
+ '-s', self.core.settings.value('outputWidth')+'x'+self.core.settings.value('outputHeight'), # size of one frame
'-pix_fmt', 'rgb24',
- '-r', self.settings.value('outputFrameRate'), # frames per second
+ '-r', self.core.settings.value('outputFrameRate'), # frames per second
'-i', '-', # The input comes from a pipe
'-an',
'-i', inputFile,
'-acodec', acodec, # output audio codec
- '-b:a', self.settings.value('outputAudioBitrate'),
- '-vcodec', self.settings.value('outputVideoCodec'),
- '-pix_fmt', self.settings.value('outputVideoFormat'),
- '-preset', self.settings.value('outputPreset'),
- '-f', self.settings.value('outputFormat')]
+ '-b:a', self.core.settings.value('outputAudioBitrate'),
+ '-vcodec', self.core.settings.value('outputVideoCodec'),
+ '-pix_fmt', self.core.settings.value('outputVideoFormat'),
+ '-preset', self.core.settings.value('outputPreset'),
+ '-f', self.core.settings.value('outputFormat')]
if acodec == 'aac':
ffmpegCommand.append('-strict')