优化图像一次,避免再次执行 [英] Optimize an image once and avoid doing it again
问题描述
我有大量的图像存储库,主要是JPEG,我想使用像ImageMagick这样的库或像jpegtran这样的Linux CLI工具进行优化(如 JPG文件大小优化 - PHP,ImageMagick和Google的页面速度),但我不想必须跟踪哪些已经优化,我不想再次优化每一个。是否有某种标志我可以轻松添加到文件中,以便于检测和跳过优化?最好是在备份到其他文件系统时保留文件的那个?
I have a large respository of images, mostly JPEG, which I'd like to optimize using a library like ImageMagick or a Linux CLI tool like jpegtran (as covered in JPG File Size Optimization - PHP, ImageMagick, & Google's Page Speed), but I don't want to have to track which ones have been optimized already and I don't want to re-optimize every one again later. Is there some sort of flag I could easily add to the file that would make it easy to detect and skip the optimization? Preferably one that would stay with the file when backed up to other filesystems?
例如:一小段exif数据,一个文件系统标志,一些无害的空字节添加在文件的结尾,一个已经足够聪明的工具,等等。
E.g.: a small piece of exif data, a filesystem flag, some harmless null bytes added at the end of the file, a tool that is already intelligent enough to do this itself, etc..
推荐答案
你可以使用扩展属性,它们是元数据并存储在文件系统中。使用 xattr
读取和写入它们:
You could use "extended attributes" which are metadata and stored in the filesystem. Read and write them with xattr
:
# Read existing attributes
xattr -l image.png
# Set an optimised flag of your own invention/description
xattr -w optimised true image.png
# Read attributes again
xattr -l image.png
optimised: true
存在可以在长列表中检测到扩展属性 - 在权限之后是 @
符号:
The presence of an extended attribute can be detected in a long listing - it is the @
sign after the permissions:
-rw-r--r--@ 1 mark staff 275 29 May 07:54 image.png
正如您在评论中提到的那样,请确保您使用的任何备份程序都遵守这些属性,然后再将其作为策略提交。 FAT-32文件系统在这种情况下是出了名的穷人 - 虽然 tar
文件或类似文件可能会在Windows-land和back之后幸存下来。
As you allude in your comments, make sure that any backup programs you use honour the attributes before committing to it as a strategy. FAT-32 filesystems are notoriously poor at this sort of thing - though tar
file or similar may survive a trip to Windows-land and back.
作为替代方案,只需在EXIF标题中设置注释 - 我已在这个相关答案......
As an alternative, just set a comment in the EXIF header - I have already covered that in this related answer...
这篇关于优化图像一次,避免再次执行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!