利⽤Python轻松⽣成艺术签名
⽬录
⼀、写在前⾯
⼆、先看看效果
三、代码展⽰
1.需要⽤到的模块
2.窗⼝名字/图标/⼤⼩/布局
3.必要组件的定义
4.输⼊框
5.保存/⽣成按钮
6.下拉框
7.组件布局
8.事件绑定
9.⽣成签名
10.更新界⾯上的图⽚
11.签名保存
12.run
四、全部代码
⼀、写在前⾯
很多兄弟觉得⾃⼰字写的不好什么的,没事,咱们直接⽤python来⽣成,对着多练练就能写出⼀⼿好看的艺术签名了,⼩看了直呼好看~
⼆、先看看效果
可以选择字体、颜⾊,这⾥我们⽤默认的看看的效果。
啊这,⼀笔学不来,算了,咱们敲代码吧…
三、代码展⽰
1.需要⽤到的模块
import requests
from PIL import Image
from PyQt5.QtGui import *
from PyQt5.QtWidgets import *
from PyQt5 import QtWidgets, QtGui
2.窗⼝名字/图标/⼤⼩/布局
self.setFixedSize(600, 500)
self.setWindowTitle('嗨学编程—艺术签名⽣成器')
self.setWindowIcon(QIcon('resource/icon/icon.jpg'))
3.必要组件的定义
self.show_label = QLabel()
self.show_label.setScaledContents(True)
self.show_label.setMaximumSize(600, 400)
self.show_image = Image.open('resource/image/ori.jpg').convert('RGB')
self.updateimage()
self.show_image_ext = 'jpg'
self.name_label = QLabel('输⼊您的姓名:')
self.font_label = QLabel('艺术签名字体:')
4.输⼊框
self.name_edit = QLineEdit()
self.name_edit.setText('签名⽣成器')
5.保存/⽣成按钮
self.save_button = QPushButton('保存艺术签名')
6.下拉框
self.font_combobox = QComboBox()
for item in ['⼀笔艺术签', '连笔商务签', '⼀笔商务签', '真⼈⼿写', '暴躁字']:
self.font_combobox.addItem(item)
for item in ['Black', 'Blue', 'Red', 'Green', 'Yellow',
'Pink', 'DeepSkyBlue', 'Cyan', 'Orange', 'Seashell']:
7.组件布局
self.id)
8.事件绑定
self.save_t(self.save)
9.⽣成签名
def generate(self):
font2ids_dict = {
'⼀笔艺术签': ['901', '15'],
'连笔商务签': ['904', '15'],
'⼀笔商务签': ['905', '14'],
'真⼈⼿写': ['343', '14'],
'卡通趣圆字': ['397', '14'],
'暴躁字': ['380', '14']
}
color2ids_dict = {
'Black': ['#000000', '#FFFFFF'],
'Blue': ['#0000FF', '#FFFFFF'],
'Red': ['#FF0000', '#FFFFFF'],
'Green': ['#00FF00', '#FFFFFF'],
'Yellow': ['#FFFF00', '#FFFFFF'],
'Pink': ['#FFC0CB', '#FFFFFF'],
'DeepSkyBlue': ['#00BFFF', '#FFFFFF'],
'Cyan': ['#00FFFF', '#FFFFFF'],
'Orange': ['#FFA500', '#FFFFFF'],
'Seashell': ['#FFF5EE', '#FFFFFF']
}
url = 'www.jiqie/a/re14.php'
headers = {
'Referer': 'www.jiqie/a/14.htm',
'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/81.0.4044.129 Safari/537.36', 'Host': 'www.jiqie',
'Origin': 'www.jiqie'
}
ids_0 = font2ids_dict[self.font_combobox.currentText()]
ids_1 = color2ids_lor_combobox.currentText()]
data = {
'id': self.(),
'zhenbi': '20191123',
'id1': ids_0[0],
'id2': ids_0[1],
'id3': ids_1[0],
'id5': ids_1[1]
}
res = requests.post(url, headers=headers, data=data)
image_url = re.findall(r'src="(.*?)"', )[0]
self.show_image_ext = image_url.split('.')[-1].split('?')[0]
res = (image_url)
fp = open('tmp.%s' % self.show_image_ext, 'wb')
fp.t)
fp.close()
self.show_image = Image.open('tmp.%s' % self.show_image_ext).convert('RGB')
self.updateimage()
10.更新界⾯上的图⽚
def updateimage(self):
if self.show_image is None:
return
fp = io.BytesIO()
self.show_image.save(fp, 'JPEG')
qtimage = QtGui.QImage()
qtimage.value(), 'JPEG')
qtimage_pixmap = QtGui.QPixmap.fromImage(qtimage)
self.show_label.setPixmap(qtimage_pixmap)
11.签名保存
def save(self):
if self.show_image is None:
returngetsavefilename
filename = SaveFileName(self, '保存', './sign.%s' % self.show_image_ext, '所有⽂件(*)') if filename[0]:
self.show_image.save(filename[0])
QDialog().show()
12.run
if __name__ == '__main__':
app = QApplication(sys.argv)
gui = ArtSignGenerator()
gui.show()
<_())
四、全部代码
我从来不吝啬源码,都直接放出来,不像那些,哈哈哈,懂的都懂。
import os
import re
import io
import sys
import requests
from PIL import Image
from PyQt5.QtGui import *
from PyQt5.QtWidgets import *
from PyQt5 import QtWidgets, QtGui
class ArtSignGenerator(QWidget):
def __init__(self, parent=None):
super(ArtSignGenerator, self).__init__(parent)
self.setFixedSize(600, 500)
self.setWindowTitle('嗨学编程—艺术签名⽣成器')
self.setWindowIcon(QIcon('resource/icon/icon.jpg'))
self.show_label = QLabel()
self.show_label.setScaledContents(True)
self.show_label.setMaximumSize(600, 400)
self.show_image = Image.open('resource/image/ori.jpg').convert('RGB')
self.updateimage()
self.show_image_ext = 'jpg'
self.name_label = QLabel('输⼊您的姓名:')
self.font_label = QLabel('艺术签名字体:')
self.name_edit = QLineEdit()
self.name_edit.setText('签名⽣成器')
self.save_button = QPushButton('保存艺术签名')
self.font_combobox = QComboBox()
for item in ['⼀笔艺术签', '连笔商务签', '⼀笔商务签', '真⼈⼿写', '暴躁字']:
self.font_combobox.addItem(item)
for item in ['Black', 'Blue', 'Red', 'Green', 'Yellow',
'Pink', 'DeepSkyBlue', 'Cyan', 'Orange', 'Seashell']:
self.id)
self.save_t(self.save)
def generate(self):
font2ids_dict = {
'⼀笔艺术签': ['901', '15'],
'连笔商务签': ['904', '15'],
'⼀笔商务签': ['905', '14'],
'真⼈⼿写': ['343', '14'],
'卡通趣圆字': ['397', '14'],
'暴躁字': ['380', '14']
}
color2ids_dict = {
'Black': ['#000000', '#FFFFFF'],
'Blue': ['#0000FF', '#FFFFFF'],
'Red': ['#FF0000', '#FFFFFF'],
'Green': ['#00FF00', '#FFFFFF'],
'Yellow': ['#FFFF00', '#FFFFFF'],
'Pink': ['#FFC0CB', '#FFFFFF'],
'DeepSkyBlue': ['#00BFFF', '#FFFFFF'],
'Cyan': ['#00FFFF', '#FFFFFF'],
'Orange': ['#FFA500', '#FFFFFF'],
'Seashell': ['#FFF5EE', '#FFFFFF']
}
url = 'www.jiqie/a/re14.php'
headers = {
'Referer': 'www.jiqie/a/14.htm',
'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/81.0.4044.129 Safari/537.36', 'Host': 'www.jiqie',
'Origin': 'www.jiqie'
}
ids_0 = font2ids_dict[self.font_combobox.currentText()]
ids_1 = color2ids_lor_combobox.currentText()]
data = {
'id': self.(),
'zhenbi': '20191123',
'id1': ids_0[0],
'id2': ids_0[1],
'id3': ids_1[0],
'id5': ids_1[1]
}
res = requests.post(url, headers=headers, data=data)
image_url = re.findall(r'src="(.*?)"', )[0]
self.show_image_ext = image_url.split('.')[-1].split('?')[0]
res = (image_url)
fp = open('tmp.%s' % self.show_image_ext, 'wb')
fp.t)
fp.close()
self.show_image = Image.open('tmp.%s' % self.show_image_ext).convert('RGB')
self.updateimage()
def updateimage(self):
if self.show_image is None:
return
fp = io.BytesIO()
self.show_image.save(fp, 'JPEG')
qtimage = QtGui.QImage()
qtimage.value(), 'JPEG')
qtimage_pixmap = QtGui.QPixmap.fromImage(qtimage)
self.show_label.setPixmap(qtimage_pixmap)
def save(self):
if self.show_image is None:
return
filename = SaveFileName(self, '保存', './sign.%s' % self.show_image_ext, '所有⽂件(*)')
if filename[0]:
self.show_image.save(filename[0])
QDialog().show()
if __name__ == '__main__':
app = QApplication(sys.argv)
gui = ArtSignGenerator()
gui.show()
<_())
以上就是利⽤Python轻松⽣成艺术签名的详细内容,更多关于Python艺术签名的资料请关注其它相关⽂章!
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系QQ:729038198,我们将在24小时内删除。
发表评论