转换具有相同名称但扩展名不同的图像 [英] Convert images which have the same names but different extensions

查看:155
本文介绍了转换具有相同名称但扩展名不同的图像的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

例如,我有两个文件:

aaa.jpg        (with cat)
aaa.png        (with dog)

正如你所看到的,图像是不同的,尽管它们的名字相同,但它们是相同的。

As you can see, images are different, despite of their names, which are the same.

我想将这两种图像转换为单一格式。

I want to convert both these images to one single format.

此任务的基本尝试是

mogrify -format jpg *.png

但由于显而易见的原因(一个文件夹不能包含多个具有相同名称和扩展名的文件),它不起作用。

But it doesn't work, for obvious reasons (one folder cannot contain multiple files with the same name and extension).

此外,我自己的一些笔记。

Also, some notes from myself.


  1. 请注意,这只是一个例子。在现实生活中,它将是大约100-200张图像。

  1. Please note, this is just example. In real life, it would be about 100-200 images.

从我的观点来看,似乎至少存在两种​​解决此问题的方法:添加时间戳到文件名添加随机文本。我认为随机文本会更好,因为时间戳有时可能相等(如果处理速度非常快)。

From my point of view, there seems to exist at least 2 ways to fix this issue: add a timestamp to filename OR add random text. I think random text will be better because timestamps sometimes could be equal (if processing is very fast).

所以,你对这项任务有什么建议,以及如何做到这一点?谢谢。

So, what do you suggest for this task, and how it could be done? Thanks.

推荐答案

您可以使用<$ c $而不是 mogrify c>转换使用 -set filename:f 修改原始文件名,例如添加包含计数器的后缀:

Instead of mogrify you can use convert modifying the original file name with -set filename:f, for example adding a suffix containing a counter:

convert *.png -set filename:f "%t_%p" "%[filename:f].jpg"

%p %t的含义属性为:


  • %p 当前图片列表中的图片索引

  • %t 没有目录或扩展名的文件名(后缀)

  • %p index of image in current image list
  • %t filename without directory or extension (suffix)

更多详情此处

如果这是你的首发场景:

If this is your starting scenario:

aaa.jpg        
aaa.png        
bbb.jpg        
bbb.png  

最终情况如下:

aaa.jpg        
aaa.png        
bbb.jpg        
bbb.png   
aaa_0.jpg
bbb_1.jpg

这篇关于转换具有相同名称但扩展名不同的图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆