Log inRegister an accountBrowse CSDbHelp & documentationFacts & StatisticsThe forumsAvailable RSS-feeds on CSDbSupport CSDb Commodore 64 Scene Database
You are not logged in - nap
CSDb User Forums


Forums > C64 Pixeling > (offtopic): convert hex numbers of image colours into others
2011-04-28 21:44
Rough
Account closed

Registered: Feb 2002
Posts: 1829
(offtopic): convert hex numbers of image colours into others

This is not 64-related but as there are some professional graphics men here and googling didn't help...

I'm looking for a tool which lets me enter colour codes in hexadecimal of images (jpg, png, (animated) gif) and change them automatically.

e.g.
I have an image consisting of 16 colours.
lightblue is #a592ff
yellow #f7f35a
etc.

I want to change the colours to
lb #a090ff
y #f0f058

the program should give me a list of all old colours (in hex) used in the image, let me enter my new colours (in hex) and auto-convert the file.

I hope something like that exists, cause I've been looking for an hour, but didnt find anything which came close.
2011-04-28 22:18
Digger

Registered: Mar 2005
Posts: 421
You can do it in Photoshop, use File > Save for web & devices, then double click on the palette colour swatch and enter the desired value. This way you can remap the colours.
2011-04-28 22:49
Rough
Account closed

Registered: Feb 2002
Posts: 1829
Thanks. I'd prefer a small tool only for that purpose. Any other suggestions?

Preferable with the option to load new palettes, so I don't need to enter the hex numbers by hand anytime, and necessarily an auto batch option.
2011-04-29 06:09
Mr. SID

Registered: Jan 2003
Posts: 421
#!/usr/bin/python

import sys
from PIL import Image

color_changes = [
[(0xA5, 0x92, 0xFF), (0xA0, 0x90, 0xFF)],
[(0xF7, 0xF3, 0x5A), (0xF0, 0xF0, 0x58)],
]

inputFile = sys.argv[1]
outputFile = sys.argv[2]

image = Image.open(inputFile)

for y in range(image.size[1]):
	for x in range(image.size[0]):
		color = image.getpixel((x, y))[0:3]
		for color_pair in color_changes:
			if color_pair[0] == color:
				color = color_pair[1]
		image.putpixel((x, y), color)

image.save(outputFile, image.format)


I'm sure someone can make this more elegant, but for a single purpose this should work.
Learn Python, it might save your life one day...
2011-04-29 16:09
Digger

Registered: Mar 2005
Posts: 421
Impressive. Python is on my list to learn. If only it had brackets ;-)
2011-04-29 19:22
Hein

Registered: Apr 2004
Posts: 933
Create your swatch-palet in Photoshop, save it (.ACO) and use it to remap your images to indexed color from RGB color. Not sure if batching records it all correctly, tho.
RefreshSubscribe to this thread:

You need to be logged in to post in the forum.

Search the forum:
Search   for   in  
All times are CET.
Search CSDb
Advanced
Users Online
tomz/TIDE
A3/AFL
E$G/hOKUtO fOrcE
Grue/Extend
Alakran_64
Frostbyte/Artline De..
curtcool
Andy/AEG
Sokrates
Guests online: 116
Top Demos
1 Next Level  (9.8)
2 Mojo  (9.7)
3 Coma Light 13  (9.7)
4 Edge of Disgrace  (9.6)
5 Comaland 100%  (9.6)
6 No Bounds  (9.6)
7 Uncensored  (9.6)
8 Wonderland XIV  (9.6)
9 Bromance  (9.6)
10 Memento Mori  (9.6)
Top onefile Demos
1 It's More Fun to Com..  (9.7)
2 Party Elk 2  (9.7)
3 Cubic Dream  (9.6)
4 Copper Booze  (9.5)
5 Rainbow Connection  (9.5)
6 TRSAC, Gabber & Pebe..  (9.5)
7 Onscreen 5k  (9.5)
8 Wafer Demo  (9.5)
9 Dawnfall V1.1  (9.5)
10 Quadrants  (9.5)
Top Groups
1 Oxyron  (9.3)
2 Nostalgia  (9.3)
3 Booze Design  (9.3)
4 Censor Design  (9.3)
5 Crest  (9.3)
Top Musicians
1 Rob Hubbard  (9.7)
2 Jeroen Tel  (9.7)
3 Stinsen  (9.6)
4 Mutetus  (9.6)
5 Linus  (9.6)

Home - Disclaimer
Copyright © No Name 2001-2024
Page generated in: 0.056 sec.