jpegtran 优化而不更改文件名
我需要优化一些图像,但不更改它们的名称。
jpegtran -copy none -optimize image.jpg > image.jpg
但是,这似乎创建了 0 的文件大小。当我对不同的文件名执行此操作时,大小仍然完全相同。
I need to optimize some images, but not change their name.
jpegtran -copy none -optimize image.jpg > image.jpg
However, this seems to create an filesize of 0. When i do it to a different filename, the size is still exactly the same.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(6)
怎么样:
我无论如何都不是 shell 专家,但我认为使用您的原始命令,一旦执行它,就会设置重定向,从而覆盖您的 image.jpg。然后,当 jpegtran 尝试读取它时,它会发现一个空文件。
how about:
I'm not a shell expert by any means, but I think that with your original command, as soon as it is executed, the redirect is set up which overwrites your image.jpg. Then when jpegtran tries to read it in it finds an empty file.
我使用这个脚本。工作完美。我希望这有帮助。
https://gist.github.com/iimos/7424025
用法 1:
用法 2:
I use this script. Works flawlessly. I hope this helps.
https://gist.github.com/iimos/7424025
Usage 1:
Usage 2:
对于全面优化:-copy none 告诉 jpegtran 抑制源 jpeg 中存在的所有注释和其他多余包袱,progressive 生成渐进式 jpeg,-optimize 执行实际的优化,-outfile 设置输出文件名。最后一个参数是输入文件名:如果它们相同,您的文件就会就地优化。
编辑:您可能还想尝试一下 mozjpeg,根据这篇有关无损 jpeg 压缩工具的文章
For comprehensive optimization: -copy none tells jpegtran to suppress all comments and other excess baggage present in the source jpeg, progressive generates a progressive jpeg, -optimize performs the actual optimizations, and -outfile sets the output file name. The last parameter is the input file name: if they are the same, your file is optimized in place.
Edit: you might want to also try mozjpeg, according to this article on lossless jpeg compression tools http://blarg.co.uk/blog/comparison-of-jpeg-lossless-compression-tools
我用三行字做了:
效果很好。
[编辑:] 这一次仅适用于一个文件。
I did it in three lines:
Works well.
[edit:] This works only for one file at a time.
如果不支持
-outfile
,则另一种选择:sponge
是 更多实用程序。Another option if
-outfile
is not supported:sponge
is part of moreutils.如果没有海绵,HDD 或 SSD 写入访问权限较低的另一种选择是使用 /dev/shm 保存临时文件,然后立即在本地覆盖它。
这个概念可以很容易地适应任何脚本,也许需要注意临时文件名不相同,以避免同时运行多个实例时发生冲突。考虑一些独特的文件名模式生成方案可能很有趣,也许类似于
${originalfilename}-jpgtrantmp-$$
。Without sponge, another alternative with lower HDD or SSD writing access is to use the /dev/shm to save the temporary file and then overwrite it locally right away.
The concept can be easily adapted into any script, perhaps with caveats about the temporary filename not being the same, in order to avoid collisions if there are multiple instances running at the same time. It's possibly interesting to think about some unique filename pattern generation scheme, perhaps something along the lines of
${originalfilename}-jpgtrantmp-$$
.