test页首

import os
from PIL import Image
# 2022-10-03
class imgcut():
    def getpaths(self):
        '''输入目录,返回图片的绝对路径列表'''
        while True:
            dir=input('请输入目录路径: ')
            paths=[]
            for f in os.listdir(dir):
                if f.endswith(('.png','.jpg','.jpeg','.gif')) :
                    paths.append(f)
            if paths==():
                print('路径错误或者当前路径没有图片,请重新输入: ')
                continue
            print('识别到的文件:\n', paths)
            return dir,paths

    def crop(self):
        dir,paths=self.getpaths()
        x,y=input('请输入长和宽(空格隔开): ').split()
        x,y=int(x),int(y)
        # x,y过大会补充图片
        for path in paths:
            img = Image.open(os.path.join(dir,path))
            x0, y0 = img.size
            box = [(x0 - x) // 2, (y0 - y) // 2, (x0 + x) // 2, (y0 + y) // 2] #centercrop
            imgnew=img.crop(box)
            name,ext=os.path.splitext(path)
            savedir,savename=dir+'\\crop\\',name+'_'+ext

            if not os.path.exists(savedir):
                os.makedirs(savedir)  
            imgnew.save(savedir+savename)
            print('save:',savedir+savename)
        pass

    def resize(self):
        dir,paths=self.getpaths()
        x,y=input('请输入长和宽(空格隔开,若等比例缩放另其中一个为-1): ').split()
        x,y=int(x),int(y)
        # x,y过大会补充图片
        for path in paths:
            img = Image.open(os.path.join(dir,path))
            x0,y0=img.size
            x=int(y/y0*x0) if x==-1 else x
            y=int(x/x0*y0) if y==-1 else y
            imgnew=img.resize((x,y),Image.ANTIALIAS)#NEAREST,BILINEAR,LANCZOS,ANTIALIAS
            name,ext=os.path.splitext(path)
            savedir,savename=dir+'\\',name+'_'+ext
            if not os.path.exists(savedir):
                os.makedirs(savedir)  
            imgnew.save(savedir+savename)
            print('save:',savedir+savename)
        pass

    def menu(self):
        print('格式需要再添加')
        print('默认采用中心裁剪')
        while True:
            print('-----------------------')
            print('1. 图片裁剪')
            print('2. 图片伸缩')
            print('-1. 退出')

            c=input()
            if c=='1':
                self.crop()
            elif c=='2':
                self.resize()
            elif c=='-1':
                break
            else:
                print('请重新输入:')
            

    def custom(self):
        pass

imgcut().menu()
posted @ 2022-10-03 11:08 开饭了没 阅读(43) 评论(0) 推荐(0) 编辑
摘要: #SingleInstance, Force #Include <JSON> ; JSON库: https://github.com/cocobelgica/AutoHotkey-JSON ; 参考小海 cosea https://zhuanlan.zhihu.com/p/103357456 ; t 阅读全文
posted @ 2022-10-03 00:23 开饭了没 阅读(308) 评论(0) 推荐(0) 编辑
摘要: 例如 f=2xsin(1/x)-cos(1/x) 且f(0)=0 有原函数F = x^2*sin(1/x) ,F(0)=0 阅读全文
posted @ 2022-10-01 05:30 开饭了没 阅读(171) 评论(0) 推荐(0) 编辑
摘要: 基于百度的paddleOCR https://zhuanlan.zhihu.com/p/521042883 github.com/hiroi-sora/Umi-OCR 阅读全文
posted @ 2022-09-30 20:23 开饭了没 阅读(572) 评论(0) 推荐(0) 编辑
摘要: 1.设置开机启动项 win r shell:startup (即C:\Users\79481\AppData\Roaming\Microsoft\Windows\Start Menu\Programs\Startup) 放入exe或快捷方式即可 任务管理器 启动项 2.win10下右键菜单添加打开管 阅读全文
posted @ 2022-09-30 19:52 开饭了没 阅读(17) 评论(0) 推荐(0) 编辑
摘要: AHK中文文档 https://wyagd001.github.io/zh-cn/docs/Hotstrings.htm 热字串 AHK中文文档 https://wyagd001.github.io/zh-cn/docs/Hotstrings.htm ; 例如 :*si:wqz::wwwqqqzzz 阅读全文
posted @ 2022-09-30 19:42 开饭了没 阅读(89) 评论(0) 推荐(0) 编辑
摘要: win10下右键菜单添加打开cmd: https://blog.csdn.net/zengxingyuluo/article/details/106887533 阅读全文
posted @ 2022-09-30 19:08 开饭了没 阅读(6) 评论(0) 推荐(0) 编辑
摘要: import pyperclip pyperclip.copy(text) 把text字符串中的字符复制到剪切板 text = pyperclip.paste() 把剪切板上的字符串复制到text 阅读全文
posted @ 2022-09-29 15:24 开饭了没 阅读(11) 评论(0) 推荐(0) 编辑
摘要: 略 阅读全文
posted @ 2022-09-23 18:54 开饭了没 阅读(7) 评论(0) 推荐(0) 编辑
摘要: # 1 print('11122223344444'.lstrip('123')) #44444 ,匹配时不是按照整个字符串匹配的,而是一个个匹配的。 # 2 'xxxx'.replace('xx','x*x') #x*xx*x #解决方法 while cmd!=cmd.replace('xx',' 阅读全文
posted @ 2022-09-21 22:16 开饭了没 阅读(15) 评论(0) 推荐(0) 编辑

test页脚

点击右上角即可分享
微信分享提示