Page 1 of 1

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

Posted: 2016-07-20T06:51:07-07:00
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.

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

Posted: 2016-07-20T07:16:00-07:00
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.

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

Posted: 2016-07-20T07:46:15-07:00
by imname
snibgo, that's awesome, thank you! Just what I wanted.