It's ok. Make a polka dot wallpaper using Python and PIL (Python Image Library) You need to install PIL and Python in advance. Refer to the bottom for installation.
It takes two arguments. The format of the two arguments is the same, which is the HLS format color specification separated by :. Note that the hsl notation supported by CSS3 and the order of the arguments are different.
360:100:100
The number before the first: is Hue (hue). It takes a value from 0 to 360.
The next number is Luminance. It takes a value from 0 to 100.
The last number is Saturation. It takes a value from 0 to 100.
By specifying two of these values, you can specify the color of the polka dot circle.
wallpaper.py 84:84:84 164:98:84
Since antialiasing can be applied only when the image is reduced in Python Image Library, the image size is fixed at 100 * 100 and displayed in your image viewer. Display it with IrfanView etc., reduce it, and save it in the format of your choice (I did this because IrfanView has more and more powerful image reduction algorithms).
The code to convert to the color code format that can be used from RGB to PIL is the one on the following site.
wallpaper.py
# -*- coding: utf-8 -*-
from PIL import Image
from PIL import ImageDraw
import colorsys
import sys
### http://code.activestate.com/recipes/266466-html-colors-tofrom-rgb-tuples/history/2/
def RGBToHTMLColor(rgb_tuple):
""" convert an (R, G, B) tuple to #RRGGBB """
hexcolor = '#%02x%02x%02x' % rgb_tuple
# that's it! '%02x' means zero-padded, 2-digit hex values
return hexcolor
def HTMLColorToRGB(colorstring):
""" convert #RRGGBB to an (R, G, B) tuple """
colorstring = colorstring.strip()
if colorstring[0] == '#': colorstring = colorstring[1:]
if len(colorstring) != 6:
raise(ValueError, "input #%s is not in #RRGGBB format" % colorstring)
r, g, b = colorstring[:2], colorstring[2:4], colorstring[4:]
r, g, b = [int(n, 16) for n in (r, g, b)]
return (r, g, b)
def HTMLColorToPILColor(colorstring):
""" converts #RRGGBB to PIL-compatible integers"""
colorstring = colorstring.strip()
while colorstring[0] == '#': colorstring = colorstring[1:]
# get bytes in reverse order to deal with PIL quirk
colorstring = colorstring[-2:] + colorstring[2:4] + colorstring[:2]
# finally, make it numeric
color = int(colorstring, 16)
return color
def PILColorToRGB(pil_color):
""" convert a PIL-compatible integer into an (r, g, b) tuple """
hexstr = '%06x' % pil_color
# reverse byte order
r, g, b = hexstr[4:], hexstr[2:4], hexstr[:2]
r, g, b = [int(n, 16) for n in (r, g, b)]
return (r, g, b)
def PILColorToHTMLColor(pil_integer):
return RGBToHTMLColor(PILColorToRGB(pil_integer))
def RGBToPILColor(rgb_tuple):
return HTMLColorToPILColor(RGBToHTMLColor(rgb_tuple))
args = sys.argv
if(len(args) != 3):
print("Args Error");
print("Usage %s [BaseHLS] [SubHLS]" % args[0])
quit()
colors = []
#Parsing arguments
for arg in args[1:]:
a = arg.split(":")
rgb1 = colorsys.hls_to_rgb(int(a[0]) / 360, int(a[1]) / 100, int(a[2]) / 100)
color = RGBToPILColor((rgb1[0] * 255, rgb1[1] * 255, rgb1[2] * 255))
print("added color:", color)
colors += [color]
img = Image.new("RGB", (100, 100), "white")
hw = img.size[0] / 2
hh = img.size[1] / 2
draw = ImageDraw.Draw(img)
for i, c in zip(range(4), colors + colors[::-1]):
im = divmod(i, 2)
r = im[0] * hw
l = im[1] * hh
print("draw point", l, "x", r)
draw.ellipse((l, r, l + hw, r + hh), fill=c)
img.show()
Recommended Posts