Page 1 of 1

Creating PNGs from hexcodes in an excel

Posted: 2016-10-07T13:59:37-07:00
by brosenBR
I'm trying to create color swatches from about 1000 hexcodes in an excel doc. I am using this http://stackoverflow.com/questions/2905 ... c7039f2aea from Stack Overflow to help guide. I can do the Image Magick portions but I'mm having difficulty pulling the hexcode from the cell(ie: A4. I know I need to use Shell Execute but I'm not sure how I get my code from Image Magick to play nice with excel. Ideally I'd also like the filename to be the text of another cell (ie: A1).

In short, I want to

Code: Select all

magick convert -size 100x100 xc:file\sheet1\cellA4 file\sheet1\cellA1.png 
Do I have this right? I'm a novice at scripting and could use some help

Re: Creating PNGs from hexcodes in an excel

Posted: 2016-10-07T14:47:22-07:00
by fmw42
Can you upload your spreadsheet to some place such as dropbox.com and put the URL here?

This will help us the put you on the right path.

Please always provide your IM version and platform, since syntax may differ, especially for scripting. It appears that you are on windows from your file paths.

You cannot use a spreadsheet or text file directly with xc:

It is expecting one color. So will likely have to parse the spreadsheet to get the cell color you need outside of IM, using your OS to parse the spreadsheet and extract the color of the cell you want. You probably want to loop over each row of the spreadsheet, get the color of the cell, then call IM to create the color swatch. You can then combine all the swatches into a montage if you want.

Re: Creating PNGs from hexcodes in an excel

Posted: 2016-10-10T06:00:39-07:00
by brosenBR
Here's the spreadsheet https://docs.google.com/spreadsheets/d/ ... sp=sharing So I'd be looking to make the color the hexcode on Cell E4 and the filename Cell F4.

I'm using version 7.0.3-2 Q16 x64 on Windows 7.

Re: Creating PNGs from hexcodes in an excel

Posted: 2016-10-10T09:21:31-07:00
by fmw42
Your file is read only. I do not see a way to download it. Nevertheless, I would convert it to a simple delimited text file. The read each row of the text file and extract the fields that you want and put them into variable. Then run the convert command on the color and the filename as output. I could do this in Unix bash shell scripting, but I do not know Windows batch scripting.

Re: Creating PNGs from hexcodes in an excel

Posted: 2016-10-10T09:55:18-07:00
by brosenBR
I updated the file so you could download. I can easily use UNIX scripting for this. Would you be able to write a script for this?

Re: Creating PNGs from hexcodes in an excel

Posted: 2016-10-10T11:53:47-07:00
by fmw42
Export your file as csv. Create a new directory and put the csv file there. I created a directory swatches on my desktop. Run the following. Replace my directory with yours

Code: Select all

cd
cd desktop/swatches
cat "BR_Team Color Codes.xlsx - NFL.csv" | tail -n +4 |\
while read line; do
hexval=`echo "$line" | cut -d, -f5`
name=`echo "$line" | cut -d, -f6`
echo "hexval=$hexval; name=$name;"
convert -size 100x100 xc:"#$hexval" "${name}.png"
done
Then you will have a directory of 100x100 images each with one color and named from the cell specified.

Re: Creating PNGs from hexcodes in an excel

Posted: 2016-10-11T14:45:17-07:00
by brosenBR
This has worked expertly. Thank you so much. For some reason, it won't read the teams from Washington, both from the NBA and NFL. Maybe the dev was from Philly. ;) Really appreciate the help saved me a lot of time

Re: Creating PNGs from hexcodes in an excel

Posted: 2016-10-11T14:56:42-07:00
by fmw42
For some reason, it won't read the teams from Washington, both from the NBA and NFL.
What do you mean by that? Is there a problem or are you making a joke!

If it is a real problem, then your tables may be different and different cells are needed or different skip of lines. Please provide those spreadsheets and what cell entries you need.