iCCP: known incorrect sRGB profile

关注公众号“码农帮派”,查看更多系列技术文章:

 
在win7系统中,微软提高了对图片质量的检测,项目中的图片可能会弹出下面的警告框:

"iccp known incorrect sRGB profile" 警告

(不同系统上的ImageMagic下载地址:http://www.imagemagick.org/script/binary-releases.php
这不是错误,但为了提高用户的体验,需要将这个框 去除,可以使用ImageMagick对图片进行转换,其实是该软件中magick.exe这个工具进行图片转换的:
e.g. 使用magick.exe对D盘下的logo_sys.png进行转换,在cmd中执行:
magick.exe D:\logo_sys.png D:\logo_sys.png
下面的程序可以批量处理文件夹下所有的图片文件:
import os
# rootPath是需要转换的图片所在的根目录
rootPath = "D:/icon"
# magick.exe所在的路径
commandTool = os.getcwdu()+os.sep+"tools"+os.sep+'magick.exe'
# 获得rootPath目录下所有图片文件的全路径
def FindExamAllFiles():
    tmp = []
    for root, dirs, files in os.walk(rootPath):
        for filepath in files:
            imgFileFullPath = os.path.join(root, filepath)
            if imgFileFullPath.endswith('.png'):
                tmp.append(imgFileFullPath)
    return tmp

if __name__ == "__main__":
    pngPathList = FindExamAllFiles()
    for pngPath in pngPathList:
        # 拼凑cmd命令
        command = "{0} {1} {2}".format(commandTool, pngPath, pngPath)
        os.system(command)
要是我们的应用会涉及到用户自主导入图片的操作,为了保证不弹出sRGB警告框,可以在每次读入图片文件之后,调用下面的函数,首先对图片进行sRGB处理: (winXP下不会有sRGB的警告,win7-32bit和win7-64bit下处理图片sRGB警告的工具版本不同)
 
import platform # 处理文件夹中单个的图片 
def convertsRGBImageFromTmp(iconName): winVerName = platform.win32_ver()[0] if winVerName != None: if winVerName.upper() == '7': arch = platform.architecture()[0] if arch.upper() == '64BIT': commandTool = os.getcwdu()+os.sep+"tools"+os.sep+'magick_64.exe'  else: commandTool = os.getcwdu()+os.sep+"tools"+os.sep+'magick.exe'   pngPath = os.getcwdu()+os.sep+'tmp'+os.sep+iconName command = "{0} {1} {2}".format(commandTool, pngPath, pngPath) try: os.system(command) except: pass  else: return  pass
因为sRGB的检测是在win7以及之后版本的系统上才有的,在XP的系统上是无需进行该操作的,Python提供了platform这个库来检测当前系统的版本,我们可以使用platform.win32_ver()[0]获得版本的名称,并进行不同的操作。
 
  • 8
    点赞
  • 16
    收藏
    觉得还不错? 一键收藏
  • 2
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值