[Image-SIG] true colors in gd
Jim Tittsler
jwt at OnJapan.net
Sun Mar 13 03:22:55 CET 2005
On Sun, Mar 13, 2005 at 02:23:32AM -0200, Necati DEMiR wrote:
> how can i use true colors by using gd library.
> for example, the following code must copy the image but it doesn't
>
> #!/usr/bin/python
>
> import gd
> inp = gd.image("input.jpg")
> gd.gdMaxColors = 256
> print inp.getClip()[1][0]+1,inp.getClip()[1][1]+1
> output = gd.image((inp.getClip()[1][0]+1,inp.getClip()[1][1]+1))
output = gd.image((inp.getClip()[1][0]+1,inp.getClip()[1][1]+1), True)
Add a third argument, which when True makes it create TrueColor
image.
> for i in range(0, inp.getClip()[1][0]+1):
> for j in range(0, inp.getClip()[1][1]+1):
> red = inp.red(inp.getPixel((i,j)))
> green = inp.green(inp.getPixel((i,j)))
> blue = inp.blue(inp.getPixel((i,j)))
> color = output.colorAllocate((red, green, blue))
You may want to use colorResolve() instead, which is smart
enough to reuse palette entries or pick the closest entry
if there are no more palette entries available. (And it
degrades to always succeeding for TrueColor images.)
> output.setPixel((i,j),color)
>
> f=open("out.png","w")
> output.writePng(f)
> f.close()
--
Jim Tittsler, Tokyo http://www.OnJapan.net/ GPG: 0x01159DB6
Python Starship http://Starship.Python.net/
Ringo MUG Tokyo http://www.ringo.net/rss.html
More information about the Image-SIG
mailing list