python图片处理

设置图片像素

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
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)

滑动图片验证

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
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 输出左上角和右下角的坐标

裁剪图片

1
2
3
4
5
6
7
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")

  

posted @   ding-ding  阅读(4)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· 微软正式发布.NET 10 Preview 1:开启下一代开发框架新篇章
· 没有源码,如何修改代码逻辑?
· PowerShell开发游戏 · 打蜜蜂
· 在鹅厂做java开发是什么体验
· WPF到Web的无缝过渡:英雄联盟客户端的OpenSilver迁移实战
点击右上角即可分享
微信分享提示