Thursday, December 31, 2020

Create a custom desktop background using Python and Paint.net

First I created a small image using paint.net image editing software.  The canvas size of this image is 30x30 pixels.  You can create any image you want.  I chose this one because I was looking for a simple dark background similar to carbon fiber or treadplate.  I have a Seagate external USB drive that had this texture on the outside and I liked the way it looked.

It is a fairly straightforward process to open this image in Python and copy it to fit the resolution of your screen using a two dimensional loop for the rows and columns.

import PIL
from PIL import Image
displayRes = (1920,1080)
black = (0,0,0)
stepSize = 30
treadPlate = Image.open("your_small_image_name.png")
image = PIL.Image.new(mode = "RGB", size = displayRes)
image.paste(black, (0,0,displayRes[0],displayRes[1]))
image.paste(treadPlate, (0,0))
for y in range(0, displayRes[1], stepSize):
    for x in range(0, displayRes[0], stepSize):
        image.paste(treadPlate, (x,y))
image.save("Background1.png","PNG", quality=100)
print(image.format, image.size, image.mode)
display(image)

 


 


 

No comments:

Post a Comment