Mogrify to output histograms with original file names

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
geoland
Posts: 74
Joined: 2015-05-14T05:11:38-07:00
Authentication code: 6789

Mogrify to output histograms with original file names

Post 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.
Version: ImageMagick 7.0.7 (latest compiled from source) Q32 x86_64 (as of) 2018 - 04 - 31 xubuntu
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Mogrify to output histograms with original file names

Post 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.
User avatar
GeeMack
Posts: 718
Joined: 2015-12-01T22:09:46-07:00
Authentication code: 1151
Location: Central Illinois, USA

Re: Mogrify to output histograms with original file names

Post 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.
geoland
Posts: 74
Joined: 2015-05-14T05:11:38-07:00
Authentication code: 6789

Re: Mogrify to output histograms with original file names

Post 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/*
Version: ImageMagick 7.0.7 (latest compiled from source) Q32 x86_64 (as of) 2018 - 04 - 31 xubuntu
Post Reply