Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Help with a recolor of a folder of images to a set of hex colors.
#1
Question 
I am trying to help my son on a project he's working on, a Minecraft mod.  but neither of us are artists.  what we need to know is if there is a way to batch process a folder of images and recolor them all outputting 118 different images from a set of 118 Hex color codes for each image.   hopefully naming each originalfileanmehexcode.png when done  if there is a tutorial for something like this out there I  would be glad to read and or watch it.  Lacking that I would be appreciative of any help anyone here would be willing to give.
Reply
#2
Is this N number single colour images, each coloured to another single colour ? That is N x 118 new images.

Can you post an example before / after image(s)
Reply
#3
Sorry this has taken so long to get back to had things come up.here are the sample files requested named as the original post stated. 

(12-13-2021, 02:49 PM)rich2005 Wrote: Is this N number single colour images, each coloured to another single colour ?  That is N x 118 new images.

Can you post an example before / after image(s)


Attached Files Image(s)
       

.txt   118 hex colors.txt (Size: 1.04 KB / Downloads: 79)
Reply
#4
My two euros worth.

For a batch operation Imagemagick (IM) http://www.imagemagick.org is more suited than Gimp.  Even so it is not going to be easy and I do not know the best way for a Windows user.

Using your examples and IM a single conversion is straight forward,  note the "#.." for the colour.

Code:
magick brick.png -colorspace gray -fill "#4c2c66" -tint 100 brick4c2c66.png

Long time since I last used a Windows .bat file (Any Windows user suggestions more than welcome)
In linux, for a single file, producing 118 variations would look like this where the file name is passed as variable $1  as: https://i.imgur.com/Svc0d3u.jpg

Gets even more complicated extracting just the tile name (without extension) in a further loop.
Sorry not a lot of help for you. You could ask on the IM forum https://github.com/ImageMagick/ImageMagick/discussions where one of the moderators is a Windows user.

Edit: Just wondering why the brick4c2c66.png filesize is larger than brick.png filesize both are RGB mode, I could not see anything obvious but it did bring up one thing. The IM script makes an indexed image. Identical to RGB version and obviously much smaller.
Attached the IM coloured file to compare:


Attached Files Image(s)
   
Reply
#5
I'm very close to what I need in my batch programming.  but still need a bit of help if any here can lend a bit of a hand.at this time I need to strip out the original file extension form my %%a variable.
Code:
echo off
SETLOCAL EnableDelayedExpansion
for /f "tokens=*" %%x in (118_hex_colors.txt) do (
    for /r %%a in (*.png) do (
    echo %%a%%x.png
        rem above line is to ensure I'm passing Image Magick the correct final file name.
        rem magick %%a -colorspace gray -fill "#%%x" -tint 100 %%a%%x.png

    )
)


' Wrote:'rich2005My two euros worth.

For a batch operation Imagemagick (IM) http://www.imagemagick.org is more suited than Gimp.  Even so it is not going to be easy and I do not know the best way for a Windows user.

Using your examples and IM a single conversion is straight forward,  note the "#.." for the colour.

Code:
magick brick.png -colorspace gray -fill "#4c2c66" -tint 100 brick4c2c66.png

Long time since I last used a Windows .bat file (Any Windows user suggestions more than welcome)
In linux, for a single file, producing 118 variations would look like this where the file name is passed as variable $1  as: https://i.imgur.com/Svc0d3u.jpg

Gets even more complicated extracting just the tile name (without extension) in a further loop.
Sorry not a lot of help for you. You could ask on the IM forum https://github.com/ImageMagick/ImageMagick/discussions where one of the moderators is a Windows user.

Edit: Just wondering why the brick4c2c66.png filesize is larger than brick.png filesize both are RGB mode, I could not see anything obvious but it did bring up one thing. The IM script makes an indexed image. Identical to RGB version and obviously much smaller.
Attached the IM coloured file to compare:
Reply
#6
Parsing the filename is always a pain. I use similar to generate several thousands tiles for picture mosaic creation where the double extension is no problem

A quick search, you have probably already seen this for Windows, https://jonlabelle.com/snippets/view/dos...-extension

On a more basic level if you can rename the 118 tiles dropping the .png extension IM will use the 'magick number' to identify the file type so (in linux) brick.png becomes brick = variable $1 and that works here:

Code:
#!/bin/bash

colval=`echo "ecbf99 d9a6ec b3ccec" `

for val in $colval
do
    magick $1  -colorspace gray -fill "#$val" -tint 100 $1$val.png
done
Reply
#7
I finally got this working with the help form here.  Thanks a bunch Rich2005!

In case anyone is interested in the solution here it is.
Code:
echo off
SETLOCAL EnableDelayedExpansion
set "slash=\"
for %%a in (*.png) do ( Rem This reads the directory for .png files that need recolor 1 at a time
    for /f "tokens=*" %%x in (118_hex_colors.txt) do ( Rem this reads in my file of hex colors 1 at a time
         if EXIST "%%~pa%%~na\" ( Rem checks if the folder that the recoloed files need to go into has been created
         echo yes
        )    else (
        mkdir "%%~pa%%~na\" Rem if not it creates it
        )    
             magick %%a -colorspace gray -fill "#%%x" -tint 100 %%~pa%%~na%slash%%%x.png
        Rem the line above does the actual recolors using image magic.
)
)
Reply


Forum Jump: