欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

Python實(shí)現(xiàn)圖片格式轉(zhuǎn)換小程序

 更新時間:2022年08月09日 17:20:28   作者:aguang5241  
這篇文章主要為大家詳細(xì)介紹了Python實(shí)現(xiàn)圖片格式轉(zhuǎn)換小程序,文中示例代碼介紹的非常詳細(xì),具有一定的參考價值,感興趣的小伙伴們可以參考一下

基于Python實(shí)現(xiàn)圖片格式轉(zhuǎn)換的小程序,供大家參考,具體內(nèi)容如下

特點(diǎn):

1.批量處理圖片
2.轉(zhuǎn)換常見的4種圖片格式

運(yùn)行窗口

運(yùn)行窗口-1

選擇圖片(可批量選擇)-2

假設(shè)選中4張JEPG格式的圖片

格式選擇窗口-3

假設(shè)選擇目標(biāo)格式PNG

結(jié)束窗口-4

結(jié)果展示-5

可以發(fā)現(xiàn)4個JEPG目標(biāo)圖片成功轉(zhuǎn)換為PNG格式的圖片

代碼

import tkinter as tk
import tkinter.messagebox
from tkinter import filedialog
from PIL import Image

def main(): ??
? ? window1 = tk.Tk()
? ? window1.title('')
? ? window1.geometry('200x100')

? ? l1 = tk.Label(window1, bg = 'green', font = ('宋體', 12), width = 50, text = '圖片轉(zhuǎn)換精靈(v1.3)')
? ? l1.pack()

? ? def select_image():
? ? ? ? image = tk.filedialog.askopenfilenames(title = '選擇圖片')
? ? ? ? num = len(image)
? ? ? ? types = ['.jpg', '.png', '.tif', '.gif']
? ? ? ? image_list = list(image)
? ? ? ??
? ? ? ? window2 = tk.Tk()
? ? ? ? window2.title('')
? ? ? ? window2.geometry('200x250')
? ? ? ??
? ? ? ? l2_1 = tk.Label(window2, bg = 'green', font = ('宋體', 12), width = 50, text = '圖片轉(zhuǎn)換精靈(v1.3)')
? ? ? ? l2_1.pack()

? ? ? ? l2_2 = tk.Label(window2, text = '')
? ? ? ? l2_2.pack()
? ? ? ??
? ? ? ? l2_3 = tk.Label(window2, font = ('宋體', 12), width = 50, text = '')
? ? ? ? l2_3.pack()
? ? ? ? l2_3.config(text = '已選擇%d張圖片' % num)
? ? ? ??
? ? ? ? l2_4 = tk.Label(window2, font = ('宋體', 12), width = 50, text = '目標(biāo)格式【點(diǎn)擊即開始】')
? ? ? ? l2_4.pack()

? ? ? ? l2_5 = tk.Label(window2, text = '')
? ? ? ? l2_5.pack()


? ? ? ? def jpg_type():
? ? ? ? ? ? image_type = types[0]
? ? ? ? ? ? for img in image_list:
? ? ? ? ? ? ? ? f = Image.open(img)
? ? ? ? ? ? ? ? img_name = img[:-4]
? ? ? ? ? ? ? ? try:
? ? ? ? ? ? ? ? ? ? f.save(img_name + image_type)
? ? ? ? ? ? ? ? except OSError:
? ? ? ? ? ? ? ? ? ? tkinter.messagebox.showerror(title='', message='%s轉(zhuǎn)換出錯' % img)

? ? ? ? ? ? tkinter.messagebox.showinfo(title='', message='轉(zhuǎn)換完成') ? ? ??

? ? ? ? def png_type():
? ? ? ? ? ? image_type = types[1]
? ? ? ? ? ? for img in image_list:
? ? ? ? ? ? ? ? f = Image.open(img)
? ? ? ? ? ? ? ? img_name = img[:-4]
? ? ? ? ? ? ? ? try:
? ? ? ? ? ? ? ? ? ? f.save(img_name + image_type)
? ? ? ? ? ? ? ? except OSError:
? ? ? ? ? ? ? ? ? ? tkinter.messagebox.showerror(title='', message='%s轉(zhuǎn)換出錯' % img)

? ? ? ? ? ? tkinter.messagebox.showinfo(title='', message='轉(zhuǎn)換完成') ? ? ??

? ? ? ? def tif_type():
? ? ? ? ? ? image_type = types[2]
? ? ? ? ? ? for img in image_list:
? ? ? ? ? ? ? ? f = Image.open(img)
? ? ? ? ? ? ? ? img_name = img[:-4]
? ? ? ? ? ? ? ? try:
? ? ? ? ? ? ? ? ? ? f.save(img_name + image_type)
? ? ? ? ? ? ? ? except OSError:
? ? ? ? ? ? ? ? ? ? tkinter.messagebox.showerror(title='', message='%s轉(zhuǎn)換出錯' % img)
? ? ? ? ? ? ? ??
? ? ? ? ? ? tkinter.messagebox.showinfo(title='', message='轉(zhuǎn)換完成') ? ? ??

? ? ? ? def gif_type():
? ? ? ? ? ? image_type = types[3]
? ? ? ? ? ? for img in image_list:
? ? ? ? ? ? ? ? f = Image.open(img)
? ? ? ? ? ? ? ? img_name = img[:-4]
? ? ? ? ? ? ? ? try:
? ? ? ? ? ? ? ? ? ? f.save(img_name + image_type)
? ? ? ? ? ? ? ? except OSError:
? ? ? ? ? ? ? ? ? ? tkinter.messagebox.showerror(title='', message='%s轉(zhuǎn)換出錯' % img)

? ? ? ? ? ? tkinter.messagebox.showinfo(title='', message='轉(zhuǎn)換完成') ? ? ??

? ? ? ? button2_1 = tk.Button(window2, text = 'JEPG', font = ('宋體', 12), width = 8, height = 1, command = jpg_type)
? ? ? ? button2_1.pack()
? ? ? ? button2_2 = tk.Button(window2, text = 'PNG', font = ('宋體', 12), width = 8, height = 1, command = png_type)
? ? ? ? button2_2.pack()
? ? ? ? button2_3 = tk.Button(window2, text = 'TIF', font = ('宋體', 12), width = 8, height = 1, command = tif_type)
? ? ? ? button2_3.pack()
? ? ? ? button2_4 = tk.Button(window2, text = 'GIF', font = ('宋體', 12), width = 8, height = 1, command = gif_type)
? ? ? ? button2_4.pack()
? ? ? ??
? ? ? ? window2.mainloop()
? ? ? ? ? ? ? ?
? ? botton1 = tk.Button(window1, text = '選擇圖片', font = ('宋體', 12), width = 8, height = 1, command = select_image)
? ? botton1.place(x = 65, y = 40)

? ? window1.mainloop()

if __name__ == '__main__':
? ? main()

以上就是本文的全部內(nèi)容,希望對大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。

相關(guān)文章

  • python?Pandas庫read_excel()參數(shù)實(shí)例詳解

    python?Pandas庫read_excel()參數(shù)實(shí)例詳解

    人們經(jīng)常用pandas處理表格型數(shù)據(jù),時常需要讀入excel表格數(shù)據(jù),下面這篇文章主要給大家介紹了關(guān)于python?Pandas庫read_excel()參數(shù)的相關(guān)資料,文中通過實(shí)例代碼介紹的非常詳細(xì),需要的朋友可以參考下
    2022-07-07
  • Python Tornado 實(shí)現(xiàn)SSE服務(wù)端主動推送方案

    Python Tornado 實(shí)現(xiàn)SSE服務(wù)端主動推送方案

    SSE是Server-Sent Events 的簡稱,是一種服務(wù)器端到客戶端(瀏覽器)的單項(xiàng)消息推送,本文主要探索兩個方面的實(shí)踐一個是客戶端發(fā)送請求,服務(wù)端的返回是分多次進(jìn)行傳輸?shù)?直到傳輸完成,這種情況下請求結(jié)束后,考慮關(guān)閉SSE,所以這種連接可以認(rèn)為是暫時的,感興趣的朋友一起看看吧
    2024-01-01
  • Python 使用 attrs 和 cattrs 實(shí)現(xiàn)面向?qū)ο缶幊痰膶?shí)踐

    Python 使用 attrs 和 cattrs 實(shí)現(xiàn)面向?qū)ο缶幊痰膶?shí)踐

    這篇文章主要介紹了Python 使用 attrs 和 cattrs 實(shí)現(xiàn)面向?qū)ο缶幊痰膶?shí)踐,本文通過實(shí)例代碼給大家介紹的非常詳細(xì),具有一定的參考借鑒價值,需要的朋友可以參考下
    2019-06-06
  • python統(tǒng)計(jì)字母、空格、數(shù)字等字符個數(shù)的實(shí)例

    python統(tǒng)計(jì)字母、空格、數(shù)字等字符個數(shù)的實(shí)例

    今天小編就為大家分享一篇python統(tǒng)計(jì)字母、空格、數(shù)字等字符個數(shù)的實(shí)例,具有很好的參考價值,希望對大家有所幫助。一起跟隨小編過來看看吧
    2018-06-06
  • python 自動去除空行的實(shí)例

    python 自動去除空行的實(shí)例

    今天小編就為大家分享一篇python 自動去除空行的實(shí)例,具有很好的參考價值,希望對大家有所幫助。一起跟隨小編過來看看吧
    2018-07-07
  • Pytest自動化測試的具體使用

    Pytest自動化測試的具體使用

    Pytest是一個Python的自動化測試框架,它可用于編寫單元測試、功能測試、集成測試和端到端測試,本文就來介紹一下Pytest自動化測試的具體使用,感興趣的可以了解一下
    2024-01-01
  • 只用四步修改jupyter的工作路徑/存儲路徑

    只用四步修改jupyter的工作路徑/存儲路徑

    為了方便用戶使用以及減少系統(tǒng)盤的占用,可以將Jupyter的默認(rèn)工作路徑修改到電腦中常用的路徑中,這篇文章主要給大家介紹了關(guān)于如何只用四步修改jupyter的工作路徑/存儲路徑的相關(guān)資料,需要的朋友可以參考下
    2023-12-12
  • Pytorch?nn.Unfold()?與?nn.Fold()圖碼詳解(最新推薦)

    Pytorch?nn.Unfold()?與?nn.Fold()圖碼詳解(最新推薦)

    這篇文章主要介紹了Pytorch?nn.Unfold()?與?nn.Fold()圖碼詳解,本文給大家介紹的非常詳細(xì),對大家的學(xué)習(xí)或工作具有一定的參考借鑒價值,需要的朋友可以參考下
    2023-05-05
  • python異常中else的實(shí)例用法

    python異常中else的實(shí)例用法

    在本篇內(nèi)容里小編給大家分享的是一篇關(guān)于python異常中else的實(shí)例用法,有興趣的朋友們可以跟著學(xué)習(xí)下。
    2021-06-06
  • Python 3.9的到來到底是意味著什么

    Python 3.9的到來到底是意味著什么

    本文主要介紹Python3.9的一些新特性比如說更快速的進(jìn)程釋放,性能的提升,簡便的新字符串函數(shù),字典并集運(yùn)算符以及更兼容穩(wěn)定的內(nèi)部API,感興趣的朋友跟隨小編一起看看吧
    2020-10-10

最新評論