import os
from PIL import Image
dir = "G:\\dev\\cs-rkbm\\rskzc2025\\yuan2\\新建文件夹0727\\新建文件夹"
dir = "G:\\dev\\cs-rkbm\\Rsbm_rpt\\zp"
dir = "G:\\dev\\cs-rkbm\\zperr"
for f in os.listdir(dir):
if os.path.isfile(os.path.join(dir,f)):
img = Image.open(os.path.join(dir,f))
if img.format != "JPEG":
print( f + " " + img.format)
if img.mode != "RGB":
print( f + " not RGB " + img.mode ) def png_to_jpg(input_path, output_path, quality=95):
"""
将PNG图片转换为JPG格式 参数:
input_path (str): 输入的PNG文件路径
output_path (str): 输出的JPG文件路径
quality (int): JPG质量,1-100,默认95
"""
try:
# 打开PNG图像
image = Image.open(input_path) # 如果图像有alpha通道(透明度),创建一个白色背景并合并
if image.mode in ('RGBA', 'LA'):
background = Image.new('RGB', image.size, (255, 255, 255))
background.paste(image, mask=image.split()[-1]) # 使用alpha通道作为掩码
image = background # 保存为JPG
image.save(output_path, 'JPEG', quality=quality)
print(f"转换成功: {input_path} -> {output_path}") except Exception as e:
print(f"转换失败: {e}") def jpgcymk_to_jpg(input_path, output_path, quality=95):
"""
将PNG图片转换为JPG格式 参数:
input_path (str): 输入的PNG文件路径
output_path (str): 输出的JPG文件路径
quality (int): JPG质量,1-100,默认95
"""
try:
# 打开PNG图像
image = Image.open(input_path) # 如果图像有alpha通道(透明度),创建一个白色背景并合并
if image.mode in ('CMYK'):
# 保存为JPG
image.save(output_path, 'JPEG', quality=quality) print(f"转换成功: {input_path} -> {output_path}") except Exception as e:
print(f"转换失败: {e}")
def bmp_to_jpg(input_file, output_file):
# 打开BMP文件
with Image.open(input_file) as im:
# 将BMP文件转换为RGB模式
rgb_im = im.convert('RGB')
# 将RGB模式的图像保存为JPEG文件
rgb_im.save(output_file, 'JPEG')

  

img convert的更多相关文章

  1. Convert BSpline Curve to Arc Spline in OpenCASCADE

    Convert BSpline Curve to Arc Spline in OpenCASCADE eryar@163.com Abstract. The paper based on OpenCA ...

  2. Convert.ToInt32()、int.Parse()和(int)三者的区别

    Convert.ToInt32将object类类型转换成int类型,如Convert.ToInt32(session["shuzi"]); (int)适合简单数据类型之间的转换: ...

  3. Leetcode: Convert sorted list to binary search tree (No. 109)

    Sept. 22, 2015 学一道算法题, 经常回顾一下. 第二次重温, 决定增加一些图片, 帮助自己记忆. 在网上找他人的资料, 不如自己动手. 把从底向上树的算法搞通俗一些. 先做一个例子: 9 ...

  4. [LeetCode] Convert a Number to Hexadecimal 数字转为十六进制

    Given an integer, write an algorithm to convert it to hexadecimal. For negative integer, two’s compl ...

  5. [LeetCode] Convert Sorted List to Binary Search Tree 将有序链表转为二叉搜索树

    Given a singly linked list where elements are sorted in ascending order, convert it to a height bala ...

  6. [LeetCode] Convert Sorted Array to Binary Search Tree 将有序数组转为二叉搜索树

    Given an array where elements are sorted in ascending order, convert it to a height balanced BST. 这道 ...

  7. 5 Convert Sorted List to Binary Search Tree_Leetcode

    Given a singly linked list where elements are sorted in ascending order, convert it to a height bala ...

  8. Unable to convert MySQL date/time value to System.DateTime 错误

    C#读取MySql时,如果存在字段类型为date/datetime时的可能会出现以下问题“Unable to convert MySQL date/time value to System.DateT ...

  9. SQL Server CONVERT() 截取日期

    SELECT CONVERT(varchar(100), GETDATE(), 0): 05 16 2006 10:57AMSELECT CONVERT(varchar(100), GETDATE() ...

  10. tomcat启动时候报错Can't convert argument: null

    一.启动报错: 为了避免导入的项目重名,我先修改了前一个项目的名称. 重新启动该项目至tomcat,报错:java.lang.IllegalArgumentException: Cant conver ...

随机推荐

  1. MCP与华为云CSE珠联璧合,打造AI时代微服务生态引擎

    本文分享自华为云社区<MCP与华为云CSE珠联璧合,打造AI时代微服务生态引擎>,作者:华为云社区精选 从 AI 技术的"火热概念"到"实际业务的落地&quo ...

  2. XSSpecter - Blind XSS 检测与管理工具

    XSSpecter 是一个模块化的盲测跨站脚本(XSS)漏洞管理工具包,包含服务端回调处理和客户端自动化测试工具. 项目概述 XSSpecter 提供两大核心组件: 服务端 - 处理XSS回调.数据持 ...

  3. 探秘Transformer系列之(34)--- 量化基础

    探秘Transformer系列之(34)--- 量化基础 目录 探秘Transformer系列之(34)--- 量化基础 0x00 概述 0x01 背景知识 1.1 需求 1.2 压缩 1.3 如何表 ...

  4. 【转载】DeltaFIFO源码分析

    DeltaFIFO源码分析 介绍 我们已经知道 Reflector 中通过 ListAndWatch 获取到数据后传入到了本地的存储中,也就是 DeltaFIFO 中.从 DeltaFIFO 的名字可 ...

  5. Springboot笔记<11>面向切面编程AOP

    面向切面编程AOP AOP为Aspect Oriented Programming的缩写,意为:面向切面编程,通过预编译方式和运行期动态代理实现程序功能的统一维护的一种技术.AOP是Spring框架中 ...

  6. 深入浅出容器学习--Docker数据卷

    一.Docker数据卷 Docker镜像是由多个文件系统(只读层)叠加而成,当启动一个容器的时候,Docker会加载只读镜像层并在其上(镜像栈顶部)添加一个读写层.如果运行中的容器修改了现有的一个已经 ...

  7. 使用FModel提取《剑星》的资产

    前言 红色是毁灭 蓝色是冷漠 绿色是伪装 白色是虚无 黄色是...........发给我!!! 不得不说,金亨泰的审美真的是这个.向金亨泰卡卡敬礼.葱!橙! 闲话少叙,咱就听老二的,开始解包! 本文内 ...

  8. Unity Shader入门精要个人学习笔记

    Unity Shader入门精要 渲染流水线 数学基础 1.点和矢量 类型 定义 表达 含义 性质 点(point) 点 (point) 是n 维空间(游戏中主要使用二维和三维空间)中的一个位置,它没 ...

  9. Windows命令行shutdown命令和快速启动之间的一点坑

    Hybrid shutdown 自Win8.1开始,在休眠和完全关闭之外,多出一个"混合关闭(hybird shutdown)"的状态.在"控制面板\硬件和声音\电源选项 ...

  10. 基于Tensorflow的神经网络模型搭建——气温预测

    基于Tensorflow的神经网络模型搭建 环境: ​ Anaconda3 ​ python 3.8.10 ​ TensorFlow 2.3.0 ​ numpy 1.22.4 ​ Pycharm 20 ...