How to create a unique/random filename using IM only?

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
imname
Posts: 8
Joined: 2016-07-16T01:49:34-07:00
Authentication code: 1151

How to create a unique/random filename using IM only?

Post by imname »

I'm using IM for simple convert operations, like this:

Code: Select all

convert image.jpg image.png
Could you please tell, if there is any way to obtain a unique or random filename for resulting file using IM only abilities without using system variables (I have some specific environment restrictions).

As I know, IM has some randomization abilities for image processing, so I wonder if there is any opportunity to use them for file naming. Or may be to use some image properties as a filename would be nice too, like data about color or source image creation date+time.
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: How to create a unique/random filename using IM only?

Post by snibgo »

IM includes a facility for random, temporary filenames. To use this, you would need a line in a delegates file.

If you just want randomness in the output filename, that's easy, for example:

Code: Select all

convert rose: -set filename:MYNAME "%[fx:rand()]" weird_%[filename:MYNAME].png
Running this twice gave me files weird_0.150978.png and weird_0.680511.png.

However, this would overwrite any files that happened to have those names.
snibgo's IM pages: im.snibgo.com
imname
Posts: 8
Joined: 2016-07-16T01:49:34-07:00
Authentication code: 1151

Re: How to create a unique/random filename using IM only?

Post by imname »

snibgo, that's awesome, thank you! Just what I wanted.
Post Reply