卓越飞翔博客卓越飞翔博客

卓越飞翔 - 您值得收藏的技术分享站
技术文章11201本站已运行3223

批处理下载并调用exiftool清除图片ICC_PROFILE 元数据

从新浪众测下载的华为p50手机拍的图片,一开始遇到这个报错 “内存不足”。Win11使用旧版的照片查看器,一开始会有一定几率出现闪退。
图片源:https://zhongce.sina.com.cn/article/view/103759
我在看了知乎 打开图片显示Windows照片查看器无法显示图片。因为计算机上的可用内存可能不足。怎么解决?、 解决Windows图片查看器提示内存不足后,怎么解决打印问题? 。略有思索,解决办法无非三种:

一、引导你的同事或驻点客户换看图软件。

二、调试系统默认参数,操作较繁琐,使用打印机打印照片空白或其他颜色异常。

三、远程下载安装,并调用ExifTool、winhex之类的工具处理掉ICC元数据。
exiftool -icc_profile  x:/your_photo_path/xxx.jpg 


其实这也与公司有些地方真得用IE,我们所背负的“技术负债” ,同理。如果你的职业是桌面运维,应该是对这情况,比较很清楚的。顺便一提,工作性质来说,工控商显电脑的FAE侧重于硬件,外包或对内的桌维/网管更多侧重于软件及系统调试。

写到中途,在网上看到这份资料csdn-如何修复Win7照片查看器无法显示的图片,比我的批处理还是要方便些,有些重复造轮子了,既然写都写了,那就继续写吧。拿来做为实例分享也不错。

选取方案三做为实现
远程下载并解压,调用ExifTool 工具处理。

附源码:https://github.com/hoochanlon/ihs-simple/blob/main/d-bat/exifhelper.bat
测试图例:https://github.com/hoochanlon/ihs-simple/tree/main/DTRASH/exif_test_pic

@echo off
home.php?mod=space&uid=251666 ----- 下载与配置 --------------

@REM 下载 exiftool.zip
IF NOT EXIST "C:\Users\%USERNAME%\Downloads\exiftool.zip" curl -o C:\Users\%USERNAME%\Downloads\exiftool.zip https://exiftool.org/exiftool-12.59.zip 

@REM  “找不到中央目录结尾记录”,那是存档坏了,见:https://qa.1r1g.com/sf/ask/1467228241/
@REM  判断位置是否存在,解压缩并重命名
IF NOT EXIST C:\Users\%USERNAME%\Tools\exiftool.exe ^
powershell -c "Expand-Archive C:/Users/${env:UserName}/Downloads/exiftool.zip C:/Users/${env:UserName}/Tools/ -Force"&&ren C:\Users\%USERNAME%\Tools\exiftool(-k).exe exiftool.exe > nul

@REM echo 文件保存位置:C:/Users/%USERNAME%/Tools 
echo "exiftool下载与配置,已完成"

@REM ----- 使用示例 --------------
:LOOP

@REM 1. 部分系统终端默认变量目录不同
@REM 2. 单个图片演示

set /p data=请将图片或目录路径复制到终端,或输入 exit 可退出当前程序: 

IF "%data%"=="exit" GOTO END

IF EXIST %data%\ (

    @REM %%~nxf %nameonly% %extonly% %filename%
    for %%f in ("%data%\*.jpg" "%data%\*.png" "%data%\*.jpeg") do (
        echo 删除文件 "%%~nxf" 中的 ICC_PROFILE...
        C:\Users\%USERNAME%\Tools\exiftool.exe -overwrite_original -icc_profile= %%f > nul
    )

)

IF EXIST %data% (C:\Users\%USERNAME%\Tools\exiftool.exe -overwrite_original -icc_profile= %data%) else (echo "信息有误,不存在图片内容" )

GOTO LOOP
:END

echo 图片处理程序,已退出

@REM --------  调试代码(win11调用旧版照片查看器)------------

@REM reg add "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows Photo Viewer\Capabilities\FileAssociations" /v ".jpg" /t reg_sz /d "PhotoViewer.FileAssoc.Tiff" /f
@REM reg add "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows Photo Viewer\Capabilities\FileAssociations" /v ".jpeg" /t reg_sz /d "PhotoViewer.FileAssoc.Tiff" /f
@REM reg add "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows Photo Viewer\Capabilities\FileAssociations" /v ".png" /t reg_sz /d "PhotoViewer.FileAssoc.Tiff" /f
测试效果如下二图,win11建议使用原本的“照片”查看,对旧版照片查看器兼容性已经很差了。


有些图片即便有icc也能够打开,我的推测是与设备支持即设备包含该配置文件有关。不过可以坐实的是,图片打不开一定是与icc有关的。

其他
至于知乎-解决Windows图片查看器提示内存不足后,怎么解决打印问题?所提到的这些注册表信息。

Windows Registry Editor Version 5.00
;Agfa状态下 能够正常看图
[HKEY_CURRENT_USER\SOFTWARE\Microsoft\Windows NT\CurrentVersion\ICM\RegisteredProfiles]
"sRGB"="RSWOP.icm"
引用一下 brother打印机官网对 ICM 此项 的描述:

ICM profiles are used to describe the color characteristics of your printer. Your Brother printer is supplied with two ICM profiles which you can use with your software applications such as Adobe Photoshop, Quark Express etc. Generally speaking, we recommend that you use these profiles, however, by purchasing a color calibration device you are able to create your own profiles which will be optimized for your particular printer.

以及 微软对 RSWOP.icm 的描述

Some software applications manage color to ensure that the colors appearing on the monitor or sent to the printer are as accurate as possible. Color management involves converting from the source profile (the color profile of the device, such as the camera, that created the image) to the destination profile (the color profile of the device that displays or prints it). If either color profile is unavailable, the color conversion fails and the image is not displayed or printed.

The RSWOP.icm CMYK color profile targets the widely-used US SWOP printing standard. This profile is installed with Microsoft Office but is not installed by default on Windows. This causes unexpected failures in applications that manage color on some images or devices. Installing this profile will correct the problem.

最后再提供给大家学习注册表的相关权威文档:

https://admx.help
https://learn.microsoft.com/zh-cn/windows/win32/apiindex/windows-api-list
https://learn.microsoft.com/zh-cn/windows/resources/
卓越飞翔博客
上一篇: Excel转CSV(VBScript)
下一篇: Python 对大段文本进行预处理 并保存EXCEL表格
留言与评论(共有 0 条评论)
   
验证码:
隐藏边栏