Png faila izveidošana ar python

Otrdiena 29.06

import png

width = 154
height = 154
img = []
for y in range(height):
    row = ()
    for x in range(width):
        row = row + (x, max(250, 150 - x - y), y)
    img.append(row)
with open('test3.png', 'wb') as f:
    w = png.Writer(width, height, greyscale=False)
    w.write(f, img)

Izmantojot PyPNG

 

https://pypng.readthedocs.io/en/latest/ca.html

a symbol or other small design adopted by an organization to identify its products, uniform, vehicles, etc.

Logo

An icon is a small image, usually a symbol, used to graphically represent a software program, file, or function on a computer screen. Icons make it easier to recognize and locate items on your computer or features within a program.

Icon

turtle — Turtle graphics

https://docs.python.org/3/library/turtle.html#turtle.goto

Iespējas

Izvēlētais variants

Tika izvēlēta bilde.

Pārveidot uz ikonas izmēriem (64x64).

Pārveidot attēlu uz b' '

Un tad pārveidoju atpakaļ.

import base64
from PIL import Image

image = Image.open("OG.PNG")
image = image.resize((64,64),Image.ANTIALIAS)
image.save(fp="ICON.png")


with open("ICON.png", "rb") as imageFile:
    str = base64.b64encode(imageFile.read())
    str2 = str.get()
    print (str)

Attēla izmēra maiņa un pārveidošana uz b''(Bytes literals)

import PIL.Image as Image
import io
import base64
from ICON import byte_data


b = base64.b64decode(byte_data)
img = Image.open(io.BytesIO(b))
img.show()
#img.save("Final.png")

b''(Bytes literals) pārveidošana uz attēlu

Python Imaging Library.

https://pillow.readthedocs.io/en/stable/

Python io.

https://docs.python.org/3/library/io.html

Python base64.

https://docs.python.org/3/library/base64.html

import pygame
import random

pygame.init()
screen = pygame.display.set_mode((800, 600))
done = False
#Nosaukums logam un ikona tam
pygame.display.set_caption("Nosaukums")
icon = pygame.image.load("ikona.png")
pygame.display.set_icon(icon)

Learn Python in 5 Hours

Object Oriented Programming: Classes and Objects

Project: API Request to GitLab

29.06.2021

By Ričards Raitums