Keep image names but add suffix

Questions and postings pertaining to the usage of ImageMagick regardless of the interface. This includes the command-line utilities, as well as the C and C++ APIs. Usage questions are like "How do I use ImageMagick to create drop shadows?".
Post Reply
Valkarin
Posts: 3
Joined: 2017-12-08T16:40:19-07:00
Authentication code: 1152

Keep image names but add suffix

Post by Valkarin »

I have a lot of images that I would like to split in two equal sizes, but I would like to keep the original name, but add an a to the leftmost part and a b to the right most part after the split. I know how to split the images, but don't know about naming output files this way. Currently, I just name the new files split000.png. Any ideas or at least where to look?
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Keep image names but add suffix

Post by fmw42 »

What is your IM version and platform, since syntax may differ? Please always provide that when asking questions.

It is easy to add numbers, but not letters.

Code: Select all

convert lena.png -crop 50x100% +repage lena_%d.png
returns lena_0.png lena_1.png

I am not sure how one would add letters.
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Keep image names but add suffix

Post by fmw42 »

The only way I can think to do that is

Code: Select all

convert logo.png -write mpr:img +delete \
\( mpr:img -gravity west -crop 50x100%+0+0 +repage +write logo_a.png \) \
\( mpr:img -gravity east -crop 50x100%+0+0 +repage +write logo_b.png \) \
null:
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: Keep image names but add suffix

Post by snibgo »

An alternative that uses less memory (bash syntax):

Code: Select all

convert logo: -crop 50x100% +repage \
  \( -clone 0 -write logo_a.png +delete \) \
  -delete 0 \
  logo_b.png
snibgo's IM pages: im.snibgo.com
Post Reply