当前位置: 首页 > news >正文

商业网站建设知识点站长统计app软件大全

商业网站建设知识点,站长统计app软件大全,网站开发全流程图,广西网站开发供应商小编最近有一篇png图片要批量压缩,大小都在5MB之上,在网上找了半天要么就是有广告,要么就是有毒,要么就是功能复杂,整的我心烦意乱。 于是我自己用python写了一个纯净工具,只能压缩png图片,没任…

小编最近有一篇png图片要批量压缩,大小都在5MB之上,在网上找了半天要么就是有广告,要么就是有毒,要么就是功能复杂,整的我心烦意乱。

于是我自己用python写了一个纯净工具,只能压缩png图片,没任何广告。在windwos平台上使用。

指定的压缩质量:40

压缩前图片大小

压缩后图片大小

可以看到图片从5MB压缩到了 500KB。指定的质量还是降低,压缩尺寸效果还可以更大。

压缩前和压缩后图片对比

压缩前,大小5.7MB:

压缩后,大小861KB:

使用视频教程

png压缩

代码采用python编写,打包成了exe, 文件目录:

直接运行这个 "批量压缩png图片.exe" 即可。

下载地址:

https://gitee.com/lz-code/soft.git

部分代码展示

import tkinter as tk
from tkinter.filedialog import askdirectory
from tkinter.messagebox import *
import datetime
import _thread
from pathlib import Path
import osdef center_window(root, width, height):# 获取屏幕宽高screen_width = root.winfo_screenwidth()screen_height = root.winfo_screenheight()# 计算窗口左上角坐标x = (screen_width - width) // 2y = (screen_height - height) // 2# 设置窗口位置root.geometry(f'{width}x{height}+{x}+{y}')def count_files_with_extension(folder_path, extension1 , extension2):count = 0path = Path(folder_path)# 获取路径下的所有文件并打印文件名称for f in path.iterdir():if f.is_file():full_path = os.path.join(folder_path, f)source_name = full_pathif source_name.endswith(extension1) or source_name.endswith(extension2):count += 1return countdef open_img_dir(edit):path_ = askdirectory()  # 使用askdirectory()方法返回文件夹的路径if path_ == "":pass# showerror('错误', '图片目录未选择')else:edit.insert(0,path_)def start_compress(entry_dir,entry_quality):img_dir = entry_dir.get()img_quality = entry_quality.get()if img_dir.strip() == "":showerror('错误', '图片目录未选择')returnif img_quality.strip() == "":showerror('错误', '压缩质量未设置')returntry:img_quality = int(img_quality)except:showerror('错误', '压缩质量只能是整数')returnif img_quality < 0 or img_quality > 100:showerror('错误', '压缩质量在0-100之间')returndef run(img_dir,img_quality):try:## 输出路径out_dir = img_dir+"/out"append_log("创建输入路径:" + out_dir)if not os.path.exists(out_dir):os.mkdir(out_dir)path = Path(img_dir)count = 0total = count_files_with_extension(img_dir,"png","PNG")btn_start.config(text="压缩中 0/"+str(total))btn_start.config(state=tk.DISABLED)# 获取路径下的所有文件并打印文件名称for f in path.iterdir():if f.is_file():full_path = os.path.join(img_dir, f)source_name = full_pathappend_log("作业压缩完成,存储:" + out_dir)btn_start.config(state=tk.NORMAL)btn_start.config(text="开始压缩")showinfo('提示', '恭喜! 图片压缩完成!')except Exception as e:import logginglogging.exception(e)append_log(str(e))btn_start.config(state=tk.NORMAL)btn_start.config(text="开始压缩")_thread.start_new_thread(run , (img_dir,img_quality))def append_log(log):current_time = datetime.datetime.now().strftime("%Y-%m-%d-%H:%M:%S")log = "["+current_time+"]# " + log + "\n"text.insert(tk.END, log + "\n")text.see(tk.END)root = tk.Tk()
root.title("批量PNG压缩 by 【轻量小工具工作室*QQ:3571289092】")
window_width = 500
window_height = 500
center_window(root, window_width, window_height)uiHeight = 30
padding = 20hint = tk.Label(root, text="                   ★★★ 无收费,无广告,无毒,自主研发,联系开发可定制 ★★★")
hint.place(x=padding, y=0, width=400, height=uiHeight)hint2 = tk.Label(root, text="压缩质量")
hint2.place(x=padding, y=uiHeight+padding, width=100, height=uiHeight)entry_quality=tk.Entry(root,bd=2)
entry_quality.place(x=padding+100, y=uiHeight+padding, width=100, height=uiHeight)
entry_quality.insert(0,40)hint2 = tk.Label(root, text="0[差]-100[好]")
hint2.place(x=2*padding+2*100, y=uiHeight+padding, width=80, height=uiHeight)hint2 = tk.Label(root, text="PNG图片路径 ")
hint2.place(x=padding, y=2*uiHeight+2*padding, width=100, height=uiHeight)entry_dir=tk.Entry(root,bd=2)
entry_dir.place(x=padding+100, y=2*uiHeight+2*padding, width=300, height=uiHeight)btn = tk.Button(root, text ="选择...", command=lambda :open_img_dir(entry_dir))
btn.place(x=2*padding+100+300, y=2*uiHeight+2*padding, width=50, height=uiHeight)btn_start = tk.Button(root, text ="开始压缩", command=lambda :start_compress(entry_dir,entry_quality))
btn_start.place(x=padding+100, y=3*uiHeight+3*padding, width=150, height=uiHeight)## 滚动的日志text = tk.Text(root , bg='black', fg='white')
scrollbar = tk.Scrollbar(root, command=text.yview)
scrollbar.pack(side=tk.RIGHT, fill=tk.Y)
scrollbar.place(x=500-padding, y=4*uiHeight+4*padding, width=10, height=uiHeight)
text.place(x=padding, y=4*uiHeight+4*padding, width=500-2*padding, height=280)root.mainloop()
http://www.ds6.com.cn/news/55635.html

相关文章:

  • 企业网站建设专家网上商城网站开发
  • 网站运营合同百度图片搜索网页版
  • 北京免费建网站推广普通话手抄报内容文字
  • 视频网站开发源码兰州网络推广关键词优化
  • flash网站首页中国十大网络销售公司
  • 长沙 学校网站建设百度电脑版下载安装
  • 武汉网站建设兼职2017搜狐财经峰会
  • 南京高端网站制作公司系统开发
  • 怎么自己制作一个网站的书源cpa推广平台
  • 最火爆的国际贸易网站在线crm管理系统
  • 中山高端网站建设网络营销推广工具
  • wordpress cdn 规则seo站长网怎么下载
  • 淘宝上做网站行吗班级优化大师的功能
  • 天津七七一网站建设有限公司怎么样成都网站优化平台
  • 做网站济南35个成功的市场营销策划案例
  • 简洁企业网站模板百度公司推广电话
  • 海城做网站公司一级域名生成二级域名
  • 医疗网站建设讯息seo网站优化流程
  • wordpress怎么做论坛seo外链专员
  • 本地的唐山网站建设网络软文营销案例
  • 怎么做装修网站平台精准营销平台
  • 用ps怎么做网站背景云搜索app官网
  • 企业网站 合同合肥网站优化seo
  • 做的比较好的公司网站浏览器网址
  • 西安做企业网站排名完整企业网站模板
  • 湖南铁军工程建设有限公司网站广州网站设计实力乐云seo
  • 自适应网站开发seo哈尔滨百度搜索排名优化
  • 网站建设调查表友情链接免费发布平台
  • 怎样创办自己的公众号郑州seo线下培训
  • 渭南建设工程信息网惠州seo代理商