Question

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!

Was it helpful?

Solution

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

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top