'''Image Resize Project
By : @_python.py_
pip install python-resize-image
'''
import tkinter.ttk
from PIL import Image, ImageTk
import PIL.Image
from resizeimage import resizeimage
from tkinter import *
from tkinter import filedialog
# make Windows
root = Tk()
root.geometry('320x480')
root.title('Image Converter @_python.py_')
root.config(bg="#ffffff")
# set image on background
image = PIL.Image.open('img.jpeg')
test = ImageTk.PhotoImage(image)
Label(image = test, bg='#fff').pack()
# defina label for app name and developer name
Label(root, text='Image Converter', font='Verdana 20 bold', fg='#404042', bg="#ffffff").pack()
Label(root, text='@_python.py_', font='Verdana 10 bold', fg='#404042', bg="#ffffff").pack()
# variables for ask image width and height
width = IntVar()
height = IntVar()
# Define Label and Entry box for ask image size
Label(root, text='Size = ', font='Verdana 10 bold', fg='#404042', bg="#ffffff").place(x=10, y=280)
Label(root, text='X', font='Verdana 10 bold', fg='#404042', bg="#ffffff").place(x=166, y=280)
Label(root, text='Width', fg='#404042', bg="#ffffff").place(x=70, y=250)
Label(root, text='height', fg='#404042', bg="#ffffff").place(x=195, y=250)
# Entry Box
Entry(root, textvariable=width, font='Verdana 10 bold', fg='#404042', bg="#ffffff", borderwidth=3, width=9).place(x=70, y=280)
Entry(root, textvariable=height, font='Verdana 10 bold', fg='#404042', bg="#ffffff", borderwidth=3, width=9).place(x=190, y=280)
Label(root, text='Select Target Format', font='Verdana 10 bold', fg='#404042', bg="#ffffff").place(x=10, y= 330)
from1 = StringVar()
jpgto = tkinter.ttk.Combobox(root, width=10, textvariable= from1)
jpgto['values'] = (' PNG', ' GIF', ' ICO')
jpgto.place(x = 190, y = 330)
jpgto.current(0)
# function for select file for browser
def ChooseFile():
global filename
# Browse Files
filename=filedialog.askopenfilename(initialdir="/", title="Select a File",
filetypes=(("JPG File", "*.jpg*"), ("all files", "*.*")))
# Change label contents
label_file_explorer.configure(text="File : "+filename)
# function for convert image
def StartConvert():
WSize = width.get()
HSize = height.get()
name = filename.split('/')
finalname = name[-1].replace('.jpeg', '')
with open(str(filename), 'r+b') as f:
with PIL.Image.open(f) as image:
cover = resizeimage.resize_cover(image, [WSize, HSize])
cover.save(f'{finalname}.{from1.get().strip().lower()}', image.format)
Label(root, text='Image Convert Successfully', fg='#404042', bg="#ffffff",font='Verdana 10 bold').place(x=57, y=410)
# label for file explore
label_file_explorer = Label(root, text="File: ", width=50, height=4, fg="#404042", bg="#ffffff")
label_file_explorer.pack()
# design button for call to function
Button(root, text='Choose File',bg='#404042', fg='#ffffff', font='Verdana 10 bold', command=ChooseFile).place(x=40, y=380)
Button(root, text='Start Convert', bg='#404042', fg='#ffffff', font='Verdana 10 bold', command=StartConvert).place(x=180, y=380)
Label(root, text='Here, you can find an image \n converter for your needs, \nfor example, a jpg to png converter.',fg='#404042', bg="#ffffff").place(x = 57, y=430)
root.mainloop()
没有合适的资源?快使用搜索试试~ 我知道了~
python的pillow库实现的图像调整大小转换格式程序
![preview](https://csdnimg.cn/release/downloadcmsfe/public/img/white-bg.ca8570fa.png)
共10个文件
xml:4个
png:1个
gitignore:1个
![preview-icon](https://csdnimg.cn/release/downloadcmsfe/public/img/scale.ab9e0183.png)
需积分: 3 0 下载量 86 浏览量
2024-02-28
08:26:26
上传
评论
收藏 42KB ZIP 举报
温馨提示
Pillow是Python中一个强大的图像处理库,它可以帮助我们进行图像的各种操作,比如调整大小、转换格式等。使用Pillow库,我们可以轻松地对图像进行处理,使得我们可以根据需要对图像进行各种操作。首先,我们需要安装Pillow库。我们可以使用pip命令来安装Pillow库,只需要在命令行中输入"pip install Pillow"即可。接下来,我们可以使用Pillow库提供的方法来实现图像的调整大小和格式转换。首先,我们需要导入Pillow库中的Image模块,然后使用open()方法来打开要处理的图像文件。接着,我们可以使用resize()方法来调整图像的大小,可以指定调整后的宽度和高度。然后,我们可以使用save()方法来保存调整后的图像,并可以指定保存的格式。另外,Pillow库还提供了一些其他有用的方法,比如旋转图像、裁剪图像等。我们可以根据具体的需求来选择合适的方法来对图像进行处理。总的来说,Pillow库是一个非常实用的图像处理工具,可以帮助我们轻松地对图像进行各种操作。它提供了丰富的功能和方法,让我们可以灵活地处理图像,并且可以根据需要进行调整大小、转换t图像格式。
资源推荐
资源详情
资源评论
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![rar](https://img-home.csdnimg.cn/images/20210720083606.png)
![rar](https://img-home.csdnimg.cn/images/20210720083606.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![txt](https://img-home.csdnimg.cn/images/20210720083642.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![rar](https://img-home.csdnimg.cn/images/20210720083606.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![py](https://img-home.csdnimg.cn/images/20210720083646.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![rar](https://img-home.csdnimg.cn/images/20210720083606.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![7z](https://img-home.csdnimg.cn/images/20210720083312.png)
![rar](https://img-home.csdnimg.cn/images/20210720083606.png)
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
收起资源包目录
![package](https://csdnimg.cn/release/downloadcmsfe/public/img/package.f3fc750b.png)
![folder](https://csdnimg.cn/release/downloadcmsfe/public/img/folder.005fa2e5.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/PNG.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![folder](https://csdnimg.cn/release/downloadcmsfe/public/img/folder.005fa2e5.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![folder](https://csdnimg.cn/release/downloadcmsfe/public/img/folder.005fa2e5.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
共 10 条
- 1
资源评论
![avatar-default](https://csdnimg.cn/release/downloadcmsfe/public/img/lazyLogo2.1882d7f4.png)
![avatar](https://profile-avatar.csdnimg.cn/38f8d9bd3f8a4a9cb31200141d837fcb_jackchuanqi.jpg!1)
传奇开心果编程
- 粉丝: 9592
- 资源: 397
上传资源 快速赚钱
我的内容管理 展开
我的资源 快来上传第一个资源
我的收益
登录查看自己的收益我的积分 登录查看自己的积分
我的C币 登录后查看C币余额
我的收藏
我的下载
下载帮助
![voice](https://csdnimg.cn/release/downloadcmsfe/public/img/voice.245cc511.png)
![center-task](https://csdnimg.cn/release/downloadcmsfe/public/img/center-task.c2eda91a.png)
最新资源
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈
![feedback](https://img-home.csdnimg.cn/images/20220527035711.png)
![feedback](https://img-home.csdnimg.cn/images/20220527035711.png)
![feedback-tip](https://img-home.csdnimg.cn/images/20220527035111.png)
安全验证
文档复制为VIP权益,开通VIP直接复制
![dialog-icon](https://csdnimg.cn/release/downloadcmsfe/public/img/green-success.6a4acb44.png)