Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

HSL python syntax (PIL)

I'm having a difficult time using hsl color values in my code here... My goal is to change the opacity of a pixel in an image based on how often the coordinate's index occurs in a data set. I'm pulling data from a csv file, and the only error I'm getting is that I'm using invalid hsl syntax. Here's a section of my code:

    for row in reader:
        port = int(row[0])
        opacity = int(row[1])/1000
        x = port % 255
        y = int(port/257)
        color = hsl(0, 0%, opacity)
        draw.point([(x,y)], fill=color)
        del draw  

From PIL's website, I assumed that the lightness and saturation have to both be percentages. The maximum value that row[1] could ever be is 999, so opacity will never be >1. Thank you in advance for your help!

like image 971
acfletch53 Avatar asked Jan 14 '23 04:01

acfletch53


1 Answers

PIL colors are defined as strings, not actual Python functions.

color = 'hsl(%d, %d%%, %d%%)' % (hue, saturation, luminance)
draw.point((x, y), fill=color)

http://effbot.org/imagingbook/imagedraw.htm

like image 80
thomasd Avatar answered Jan 16 '23 19:01

thomasd