Isso deve ser feito:
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
import random
from PIL import Image
from gi.repository import Gio
def get_wallpaper_uri():
settings = Gio.Settings.new("org.gnome.desktop.background")
uri = settings.get_string("picture-uri")
return uri
def uri_to_path(uri):
return uri.lstrip("file:")
def get_random_coordinates(x_max, y_max, num):
x_values = random.sample(range(x_max), num)
y_values = random.sample(range(y_max), num)
return zip(x_values, y_values)
def main():
uri = get_wallpaper_uri()
path = uri_to_path(uri)
image = Image.open(path)
width, height = image.size
coordinates = get_random_coordinates(width, height, 10)
pixels = image.load()
for coordinate in coordinates:
pixel_value = pixels[coordinate]
print(pixel_value)
if __name__ == "__main__":
main()