python修改图片格式

#!/usr/bin/env python
# -*- coding: utf-8 -*-

import os
from wand.image import Image
from struct import *

def pdfToPng():
path = "/home/siyin/素材库各20例/"
listdir = os.listdir(path)
print listdir
for dir in listdir:
basePath = path + dir + "/"
savePath = "/home/siyin/素材库各20例(png)/" + dir + "/"
if os.path.exists(savePath) == False:
os.mkdir(savePath)
fileList = os.listdir(basePath)
for file in fileList:
filePath = basePath + file
print filePath
newFileName = file.split(".")[0]
with Image(filename=filePath) as img:
if(file.split(".")[1] == "png" ):
img.save(filename=savePath+file)
else:
img.save(filename=savePath + newFileName + ".png" )
os.remove(filePath)
if __name__ == "__main__":
pdfToPng()

转载于:https://www.cnblogs.com/sy-liu/p/7058259.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值