Answers for "python save png file"

1

convert files from jpg to png and save in a new directory python

from PIL import Image
import os

directory = r'D:PATH'
c=1
for filename in os.listdir(directory):
    if filename.endswith(".jpg"):
        im = Image.open(filename)
        name='img'+str(c)+'.png'
        rgb_im = im.convert('RGB')
        rgb_im.save(name)
        c+=1
        print(os.path.join(directory, filename))
        continue
    else:
        continue
Posted by: Guest on August-21-2020
0

save image url to png python

import urllib.request

#python 3
urllib.request.urlretrieve(url, filename)
Posted by: Guest on June-14-2020
0

load png to python

import imageio

im = imageio.imread('my_image.png')
print(im.shape)
Posted by: Guest on December-04-2021
0

python how to make a png

import png
s = ['110010010011',
     '101011010100',
     '110010110101',
     '100010010011']
s = [[int(c) for c in row] for row in s]

w = png.Writer(len(s[0]), len(s), greyscale=True, bitdepth=1)
f = open('png.png', 'wb')
w.write(f, s)
f.close()

# https://pypng.readthedocs.io/en/latest/ex.html
Posted by: Guest on June-28-2021

Python Answers by Framework

Browse Popular Code Answers by Language