python--将多张图片显示在一张画布上
python--将多张图⽚显⽰在⼀张画布上
⽅法1:pillow将多张图⽚显⽰在⼀张画布上
缺点:每张画布上图⽚个数必须是给定数量
class MakeCodeAction(BaseActionView):假面骑士剧场版
# 这⾥需要填写三个属性
action_name = "create_assets_qr_code"
description = u'Create selected IT⼆维码'
model_perm = 'change'
def do_action(self,queryset):
img_list = []
for obj in queryset:
code_str = '{url}/assets/decode_code/?num={OYcode}'.format(quest.META['HTTP_HOST'],
OYcode=obj.num)
filename = CreateCode().make_code(text=code_str)
img_list.append(filename)
IMAGE_SIZE = 256  # 每张⼩图⽚的⼤⼩
IMAGE_ROW = 5  # 图⽚间隔,也就是合并成⼀张图后,⼀共有⼏⾏
IMAGE_COLUMN = 4  # 图⽚间隔,也就是合并成⼀张图后,⼀共有⼏列
IMAGE_SAVE_PATH = 'media/qrcode_all/{}.png'.format(uuid.uuid4().hex[4:])  # 图⽚转换后的地址
# 简单的对于参数的设定和实际图⽚集的⼤⼩进⾏数量判断
if len(img_list) != IMAGE_ROW * IMAGE_COLUMN:
raise ValueError("合成图⽚的参数和要求的数量不能匹配!")
# 定义图像拼接函数
import PIL.Image as Image
# def image_compose():
to_image = w('RGB', (IMAGE_COLUMN * IMAGE_SIZE, IMAGE_ROW * IMAGE_SIZE))  # 创建⼀个新图
# 循环遍历,把每张图⽚按顺序粘贴到对应位置上
for y in range(1, IMAGE_ROW + 1):
怎么下载电影到电脑里for x in range(1, IMAGE_COLUMN + 1):
from_image = Image.open(img_list[IMAGE_COLUMN * (y - 1) + x - 1]).resize((IMAGE_SIZE, IMAGE_SIZE), Image.ANTIALIAS)
to_image.paste(from_image, ((x - 1) * IMAGE_SIZE, (y - 1) * IMAGE_SIZE))
to_image.save(IMAGE_SAVE_PATH)  # 保存新图
if ists(IMAGE_SAVE_PATH):
qrimg_data = open(IMAGE_SAVE_PATH, 'rb').read()
return HttpResponse(qrimg_data, content_type="image/png")
⽅法2:opencv-pyplot多张图⽚显⽰在⼀张图⽚上
缺点:只能横向或竖向排⼀列
好听的伤感网络歌曲
import cv2
from pylab import *
美国签证状态查询
img1 = cv2.imread('logo.jpg',cv2.IMREAD_COLOR)
img2 = cv2.imread('logo.jpg',cv2.IMREAD_GRAYSCALE)
img3 = cv2.imread('logo.jpg',cv2.IMREAD_UNCHANGED)
img4 = cv2.imread('logo.jpg')
支付宝不可用余额
htitch= np.hstack((img1, img3,img4)) # 横向排列
vtitch = np.vstack((img1, img3)) # 纵向排列
cv2.imshow("test1",htitch)
cv2.imshow("test2",vtitch)
cv2.waitKey(0)
cv2.destroyAllWindows()
ImportError: No module named cv2
安装:pip2 install opencv-python==4.2.0.32
No module named 'pylab'
综合素质自我评价安装:pip2 install matplotlib
ERROR: Cannot uninstall 'pyparsing'. It is a distutils installed project and thus we cannot accurately determine which files belong to it which would lead to only a partial uninstall.
解决⽅法是⼿动重装最新版 pyparsing
sudo pip install -I pyparsing==2.2.0
pip install matplotlib
ImportError: No module named Tkinter
安装:
yum install -y tkinter
yum install -y tk-devel
DEPRECATION: Python 2.7 reached the end of its life on January 1st, 2020. Please upgrade your Python as Python 2.7 is no longer maintained. pip 21.0 will drop support for Python 2.7 in January 2021. More details about Python 2 support

版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系QQ:729038198,我们将在24小时内删除。