Batch Rename Images According to Color?
- fmw42
- Posts: 25562
- Joined: 2007-07-02T17:14:51-07:00
- Authentication code: 1152
- Location: Sunnyvale, California, USA
Re: Batch Rename Images According to Color?
In Windows, I think % need to be escape to %% in batch scripting
-
- Posts: 9
- Joined: 2017-06-01T21:48:16-07:00
- Authentication code: 1151
Re: Batch Rename Images According to Color?
Sorry, posted without seeing your reply
That's ridiculously easy now! I'm so glad I came here!fmw42 wrote: ↑2017-06-02T16:38:35-07:00 Example using the IM 7.0.5.10 beta:
produce an image named #FFFFFF.pngCode: Select all
magick logo: -depth 8 -set filename:f "%[hex:u.p{0,0}]" %[filename:f].png
Just a couple more questions:
Where can I get the new beta?
How long does it usually take to go from beta to stable? Should I just wait a day or two?
You said in your last example that the output would be "#FFFFFF.png"... Is there an easy way to leave out the "#"?
These could be removed with a bulk rename easily enough I guess... just thought I'd ask since I'm on a roll here lol!
Hmmm... really? I entered the following code with single "%" previously and it worked without the need for double %%. Will the new code be different for some reason?
Code: Select all
magick *.png -set colorspace RGB -set filename:f "%[pixel:p]" %[filename:f].png
- fmw42
- Posts: 25562
- Joined: 2007-07-02T17:14:51-07:00
- Authentication code: 1152
- Location: Sunnyvale, California, USA
Re: Batch Rename Images According to Color?
Betas are available only as source code that you need to compile. See http://magick.imagemagick.org/download/beta/
There is no particular time frame for when a beta gets officially release. It could be the next day or weeks. It depends upon how many and how significant the bug fixes are. Often release are made on the weekends, but not necessarily every weekend.
Right now there is no control for # or no #. Since this is in beta, it can be changed. I would say that perhaps it would be best to leave it off, since one can always do
magick image -depth 8 -format "#%[hex:u.p{0,0}]" info:
if one wants to add it. I have recommended the change.
% needs to be doubled, I believe only in batch scripting (.bat files). But I am not a Windows user. So I will defer to one of them to correct me. I shortly corrected my post about that above after your quote of it.
There is no particular time frame for when a beta gets officially release. It could be the next day or weeks. It depends upon how many and how significant the bug fixes are. Often release are made on the weekends, but not necessarily every weekend.
Right now there is no control for # or no #. Since this is in beta, it can be changed. I would say that perhaps it would be best to leave it off, since one can always do
magick image -depth 8 -format "#%[hex:u.p{0,0}]" info:
if one wants to add it. I have recommended the change.
% needs to be doubled, I believe only in batch scripting (.bat files). But I am not a Windows user. So I will defer to one of them to correct me. I shortly corrected my post about that above after your quote of it.
-
- Posts: 9
- Joined: 2017-06-01T21:48:16-07:00
- Authentication code: 1151
Re: Batch Rename Images According to Color?
I guess it helps to have friends in (virtual) high places eh?fmw42 wrote: ↑2017-06-02T16:59:49-07:00 Right now there is no control for # or no #. Since this is in beta, it can be changed. I would say that perhaps it would be best to leave it off, since one can always do
magick image -depth 8 -format "#%[hex:u.p{0,0}]" info:
if one wants to add it. I have recommended the change.
Luckily for me what you've said makes good logical sense! It does seem as if it's easier to add a "#" character than it is to remove one...
Ah OK... Gotchafmw42 wrote: % needs to be doubled, I believe only in batch scripting (.bat files). But I am not a Windows user. So I will defer to one of them to correct me. I shortly corrected my post about that above after your quote of it.
A final and heartfelt thanks again to you sir, you are, as the old adage goes: a scholar and a gentleman, and you have saved me much time and many clicks!
- fmw42
- Posts: 25562
- Joined: 2007-07-02T17:14:51-07:00
- Authentication code: 1152
- Location: Sunnyvale, California, USA
Re: Batch Rename Images According to Color?
Glad to have helped. I thought this would make a good addition and I hope the release comes out soon with the fix to remove the leading #
-
- Posts: 9
- Joined: 2017-06-01T21:48:16-07:00
- Authentication code: 1151
Re: Batch Rename Images According to Color?
I wondered what I might do to show my appreciation... So I came back again to say:
If you guys fmw42 or magick in particular need any sort of graphic/design work done (perhaps some new icons or whatever), just let me know and I will do it for free
If you guys fmw42 or magick in particular need any sort of graphic/design work done (perhaps some new icons or whatever), just let me know and I will do it for free
- fmw42
- Posts: 25562
- Joined: 2007-07-02T17:14:51-07:00
- Authentication code: 1152
- Location: Sunnyvale, California, USA
Re: Batch Rename Images According to Color?
We are just happy to help you and to make the ImageMagick produce more useful and flexible. We will keep it in mind. Thanks for the offer.
-
- Posts: 9
- Joined: 2017-06-01T21:48:16-07:00
- Authentication code: 1151
Re: Batch Rename Images According to Color?
Hi again...
Just popped back in to verify that the newest version of ImageMagick (7.0.6-0) now does indeed leave out the leading "#" symbol for hex color code output (awesome).
Here is the final script I ended up with (run from Windows Command Prompt):
This (for those who don't already know) will process all PNG files (script is for use with images which consist of only a single color) by:
Thanks again for all of your help... This makes this task so much easier now
Just popped back in to verify that the newest version of ImageMagick (7.0.6-0) now does indeed leave out the leading "#" symbol for hex color code output (awesome).
Here is the final script I ended up with (run from Windows Command Prompt):
Code: Select all
@ECHO OFF
FOR %a in (*.png) DO (
REN "*.png" "temp_*.png"
magick mogrify -gravity Center -crop 88x88+0+0 +repage *.png
magick *.png -depth 8 -set filename:f "%[hex:u.p{0,0}]" %[filename:f].png
DEL "temp_*.png"
)
- Adding the prefix "temp_" to all filenames
- Cropping them to 88x88px
- Making copies with filenames according to their hex color codes, for example "679D42.png"
- Deleting the originals
Thanks again for all of your help... This makes this task so much easier now
-
- Posts: 12159
- Joined: 2010-01-23T23:01:33-07:00
- Authentication code: 1151
- Location: England, UK
Re: Batch Rename Images According to Color?
If it works and you are happy, that's good.
But I notice that you loop through all of the PNG files (in the FOR loop).
Within that loop, you loop though all the files again (in the "mogrify".)
So you are repeating a lot of work. You never use "%a", so you can probably remove the FOR loop entirely.
But I notice that you loop through all of the PNG files (in the FOR loop).
Within that loop, you loop though all the files again (in the "mogrify".)
So you are repeating a lot of work. You never use "%a", so you can probably remove the FOR loop entirely.
snibgo's IM pages: im.snibgo.com
- fmw42
- Posts: 25562
- Joined: 2007-07-02T17:14:51-07:00
- Authentication code: 1152
- Location: Sunnyvale, California, USA
Re: Batch Rename Images According to Color?
This should work:
Change your crop values as desired. The only issue is if you do not have enough memory to hold all your pngs at the same time.
Note the hex: uses s.p{0,0} so that it gets each image in the command sequence. u.p{0,0} will always take the first image in the sequence.
Code: Select all
cd folder_with_pngs
magick *.png -gravity center -crop 10x10+0+0 -depth 8 -set filename:f "%[hex:s.p{0,0}]" "%[filename:f].png"
Note the hex: uses s.p{0,0} so that it gets each image in the command sequence. u.p{0,0} will always take the first image in the sequence.
- GeeMack
- Posts: 718
- Joined: 2015-12-01T22:09:46-07:00
- Authentication code: 1151
- Location: Central Illinois, USA
Re: Batch Rename Images According to Color?
All the IM operations can be done in a single command, but the renaming and deleting of the files will be done outside IM. A simple BAT script like this should get pretty close to what you're describing...WallBanger wrote: ↑2017-06-19T21:10:06-07:00I wondered if there might be some way to do this all in one step using mogrify but I'm very happy with this method anyhow.
- Adding the prefix "temp_" to all filenames
- Cropping them to 88x88px
- Making copies with filenames according to their hex color codes, for example "679D42.png"
- Deleting the originals
Code: Select all
@echo off
for %%I in ( *.png ) do ren "%%I" "temp_%%I"
magick *.png -depth 8 -resize 88x88! -set filename:f %%[hex:s.p{0,0}] %[filename:f].png
del "temp_*.png"