Made a gradient with PIL module, it turned out darker

224 views Asked by At

I was trying to use the PIL module to make the colorpicker gradient

Like this.

I made a code to test out:

from PIL import Image

img = Image.new('HSV', (255,255), "white")
pix = img.load()

H = 0
for x in range(img.size[0]):
    S =(int(100*(x/float(img.size[0])))) # A % of image width

    for y in range(img.size[1]):
        V = (int(100*(1-(y/float(img.size[1]))))) # A % of image height

        pix[x,y] = (H,S,V)

img.show()

But my image turns out dark. What did I do wrong?

1

There are 1 answers

2
jasonharper On

You are generating S and V values in the 0..100 range. However, I'm pretty sure that a PIL HSV image uses 0..255 values; in other words, you're only using the bottom 40% of the range.