my use case seems quite classic, but I did not find direct answer yet. I started to write this thread looking for a solution, but found one in between, so more a way to share and discuss it
I am using IM for a while to resize my jpg for the web. I like to put the title of the picture directly on it. I used to put it on a frame outside the pict, but would like to do it on the top left on the image itself (-gravity NorthWest).
I want to determine the color I should use to write the title.
Basically, I need to identify the mean color of the first 800x50 pixels and get the negative of it.
Actually, I even need to do it in black/white, inverting a middle color (or a middle gray if in colorspace gray) does not help much...
While looking for a solution, I ended up with the following command:
Code: Select all
convert input.jpg -crop 800x50+0+0 -threshold 50% -negate -scale 1x1\! -format '%[pixel:s]' info:-
Seems to work fine, do you have maybe even better command or additional ideas to do this job?
In my PowerShell script, I use it like that:
Code: Select all
$headlineColor = convert $file -crop 800x50+0+0 -negate -scale 1x1\! -format '%[pixel:s]' info:-
convert -size 1000x50 xc:transparent -font Candice -pointsize 20 -gravity west -draw "fill '$headlineColor' text 0,0 '$headline'" -trim +repage headline.png
#(... generating also a copyright file, calculating the size, generating the output filename, etc)
convert $file -filter Lanczos -resize $resize -unsharp 0x0.6+0.75+0.02 -format JPEG -quality 95 -gravity SouthEast $signatureFile -compose atop -geometry +4+0 -composite -gravity NorthWest headline.png -compose atop -geometry +4+0 -composite $s