python 随机字符串
pip3 install pillow
读取硬盘中的文件,在页面显示
f = open('static/imgs/yj.png','rb')
data = f.read()
f.close()
return HttpResponse(data)
创建一个空白图片
from PIL import Image
f = open('code.png','wb') #打开一个文件
img = Image.new(mode='RGB', size=(120, 30), color=(255, 255, 255)) #创建一个图片
img.save(f,'png') #图片保存在文件里
f.close()
将图片写入内存,再从内存读出来
#BytesIO 相当于开辟一段内存空间,可以读写 from PIL import Image,ImageDraw,ImageFont
from io import BytesIO f = BytesIO() #相当于开辟一段内存空间
img = Image.new(mode='RGB', size=(120, 30), color=(255, 255, 255)) #创建一个图片对象
img.save(f,"png") #内存里有图片
data = f.getvalue() #获取内存中的数据
return HttpResponse("...")
from PIL import Image,ImageDraw
from io import BytesIO
f = BytesIO()
img = Image.new(mode='RGB', size=(120, 30), color=(255, 255, 255)) #创建一个图片对象
draw = ImageDraw.Draw(img, mode='RGB') #在图片上创建一个对象 #在图片上画点
draw.point([10, 10], fill="red") #点在图片上的坐标位置
draw.point([20, 10], fill=(255, 255, 255)) #在图片上画线
draw.line((15,10,50,50), fill='red') #前两个起始位置的横纵坐标,后两个结束位置的横纵坐标
draw.line((45,20,100,100), fill=(0, 255, 0))
python 随机字符串的更多相关文章
- Python随机字符串验证码
def code_get(self): source = ['] #数字验证码 # source = [ 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H','I','J', ...
- Python学习总结7:随机字符串和随机数
Python生成随机数与随机字符串,需要import random模块.random模块最常用的几个函数如下: 1. random.random(a, b) 用于生成一个0到1的随机符点数: 0 &l ...
- Python生成随机字符串
利用Python生成随机域名等随机字符串. #!/usr/bin/env python# -*- coding: utf-8 -*- from random import randrange, cho ...
- python生成随机数、随机字符串
python生成随机数.随机字符串 import randomimport string # 随机整数:print random.randint(1,50) # 随机选取0到100间的偶数:print ...
- Python 中的POST/GET包构建以及随机字符串的生成-乾颐堂
现在,我们来用Python,创建GET包和POST包. 至于有什么用处,大家慢慢体会. Python 中包含了大量的库,作为一门新兴的语言,Python 对HTTP有足够强大的支持. 现在,我们引入新 ...
- Golang 和 Python 随机生成N位字符串
Golang: func RandomString(n int) string { var letters = []byte("ABCDEFGHIGKLMNOPQRSTUVWXYZabcde ...
- python 生成随机字符串
1.生成随机字符串 #数字+字母+符号 def getRandChar(n): l = [] #sample = '0123456789abcdefghijklmnopqrstuvwxyz!@#$%^ ...
- python(七)字符串格式化、生成器与迭代器
字符串格式化 Python的字符串格式化有两种方式:百分号方式.format方式 1.百分号的方式 %[(name)][flags][width].[precision]typecode (name) ...
- random and password 在Linux下生成crypt加密密码的方法,shell 生成指定范围随机数与随机字符串
openssl rand -hex n (n is number of characters) LANG=c < /dev/urandom tr -dc _A-Z-a-z-0-9 | head ...
随机推荐
- redis的简单事务
Redis对事务的支持目前还比较简单.Redis只能保证一个client发起的事务中的命令可以连续的执行,而中间不会插入其他client的命令.当一个client在一个连接中发出multi命令时,这个 ...
- bzoj2213: [Poi2011]Difference(思维题)
今天颓了一天T T 这题有两种写法... ①预处理出每种字符在原字符串中的位置,枚举两种字符作为最大值和最小值,把这两种字符的坐标归并排序,把最大值设为1,最小值设为-1,求最大子段和.注意因为 ...
- Python3 字典 update() 方法
Python3 字典 描述 Python 字典 update() 函数把字典dict2的键/值对更新到dict里. 语法 update()方法语法: dict.update(dict2) 参数 di ...
- Square Country
原题链接:http://acm.timus.ru/problem.aspx?space=1&num=1073 分析:dp,dp[i]表示钱为i且恰好用完时能买的最少土地数,易知dp[i]=mi ...
- valgrind检查C/C++内存泄漏
valgrind --tool=memcheck --leak-check=full ./httptest valgrind --tool=memcheck --leak-check=full -- ...
- Libevent学习笔记(五) 根据例子学习bufferevent
libevent中提供了一个Hello-world.c 的例子,从这个例子可以学习libevent是如何使用bufferevent的. 这个例子在Sample中 这个例子之前讲解过,这次主要看下buf ...
- LeetCode-Evaluate Reverse Polish Notation[AC源码]
package com.lw.leet2; /** * @ClassName:Solution * @Description: * Evaluate the value of an arithmeti ...
- springsecurity 表达式一览
表达式 描述 hasRole([role]) 当前用户是否拥有指定角色. hasAnyRole([role1,role2]) 多个角色是一个以逗号进行分隔的字符串.如果当前用户拥有指定角色中的任意一个 ...
- node.js的安装配置——前端的配置
最近琢磨了以下node.js的安装,npm的配置,使用gulp watch监听index.html文件的修改,利用服务器打开网页. 打开自己写的网页不要本地双击打开,这样打开的网址是file:///E ...
- DES加密解密类
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.S ...