设置图片像素
from PIL import Image def set_image(path, width=280): """设置图片像素""" # 打开图片 image = Image.open(path) # 原来大小 original_width, original_height = image.size # 设置新的图片大小 new_width, new_height = width, int(original_height * width / original_width) # 举例,设置新的宽度和高度约为280x200 resized_image = image.resize((new_width, new_height)) # 保存新的图片 resized_image.save(path)
滑动图片验证
import ddddocr def generate_distance(slice_image, bg_image): """滑动图片验证 :param bg_image: 背景图字节 :param slice_image: 滑块图字节 :return: distance :rtype: Integer """ slide = ddddocr.DdddOcr(det=False, ocr=False, show_ad=False) # slice_image = slice_url # requests.get(slice_url).content # bg_image = bg_url # requests.get(bg_url).content result = slide.slide_match(slice_image, bg_image, simple_target=True) # print(result) return result['target'][0] # target 输出左上角和右下角的坐标
裁剪图片
from PIL import Image # 裁剪前景图片 img = Image.open("qg.png") print("前景原图大小:", img.size) cropped = img.crop((58, 207, 58 + 50, 207 + 50)) # (left, upper, right, lower) cropped.save("qg.png")
标签:slice,width,python,image,处理,bg,new,图片 From: https://www.cnblogs.com/ding-yong/p/18360224