Page 1 of 1

Mogrify to output histograms with original file names

Posted: 2018-04-21T18:39:32-07:00
by geoland
Hi. Is there a way to write this and retain the original file name. I have tried various mogrify options without success. I can't find a way to use mogrify in this case and it seems necessary to resort to bash scripting

Code: Select all

convert *.tif -define histogram:unique-colors=false histogram:$((x++))_histogram.gif
which outputs

Code: Select all

0_histogram.gif 1_histogram.gif  and so on
Not relevant to the question but the output is then animated.

Re: Mogrify to output histograms with original file names

Posted: 2018-04-21T19:00:24-07:00
by fmw42
Mogrify processes one output per one input. So I am not sure you can use mogrify to do what you want, if I understand the question.

In the future, please always provide your Imagemagick version and platform when asking questions on this forum.

Re: Mogrify to output histograms with original file names

Posted: 2018-04-21T19:05:31-07:00
by GeeMack
geoland wrote: 2018-04-21T18:39:32-07:00Hi. Is there a way to write this and retain the original file name. I have tried various mogrify options without success. I can't find a way to use mogrify in this case and it seems necessary to resort to bash scripting
Even when working with a list of images, IM6's "convert" (or "magick" in IM7) can hold the input filename in a variable and use that to set the output filename. Try something like this...

Code: Select all

convert *.tif -set filename:f "%[t]_histogram" \
   -define histogram:unique-colors=false +adjoin histogram:"%[filename:f].gif"
Not relevant to the question but the output is then animated.
Use "+adjoin" to assure your output is separate images and not an animation.

Re: Mogrify to output histograms with original file names

Posted: 2018-04-21T20:22:23-07:00
by geoland
Thank you.

A small adjustment to leave out 'histogram' and the gif extension, leaving only the filename... and happy to have the sequence begin as an animation...

Code: Select all

convert *.tif -set filename:f '%[t]' -define histogram:unique-colors=false histogram:$tmpdir/"%[filename:f].gif"

	for i in $tmpdir/*.gif;do mv -- "$i" "${i%%.gif}";done
	
	animate -delay 50 -loop 0 -resize 200% $tmpdir/*