Questions tagged [pypng]

Pure Python library for PNG image encoding/decoding

Definition:

PyPNG provides Python code for encoding and decoding PNG files.

Example Usage:

import png
f = open('example.png', 'wb')
w = png.Writer(255, 1, greyscale=True)
w.write(f, [range(256)])
f.close()

Important Links:

35 questions
9
votes
1 answer

How to reduce the palette of PNG image in Python/Pillow to the colors being really used?

After processing a previously optimized indexed color PNG image with transparency (see here for some background, since this question refers to the same image file), using the following code, the PLTE chunk seems to be expanded with more colors than…
7
votes
1 answer

numpy.array to PNG file and back

I have a 2d numpy.array object of dtype=uint16 representing a grayscale image. How do I save it to a PNG file and then read it back, obtaining the same array?
Jonathan Livni
  • 101,334
  • 104
  • 266
  • 359
4
votes
2 answers

Convert 8 bit ( 16 Color Palette ) PNG to proper 4 bit ( 16 color Palette ) with Java or Python?

I have a bunch of images, to many to do by hand that are 16 color 8 bit PNG format that I need in 16 4 bit format, they all have the same palette. I am scouring Google for the best library to use, but I am not finding much on this specific problem…
user177800
3
votes
1 answer

Why can't I round-trip an image using PyPNG?

This seems fairly simple: import png rdr = png.Reader(filename='help.png') width, height, pixels, metadata = rdr.read() with open('help-new.png', 'w') as outfile: png.Writer(**metadata).write(outfile, pixels) However, I can't open my new image…
samwyse
  • 2,760
  • 1
  • 27
  • 38
3
votes
0 answers

Create a RGB 565 image from python array

I've got a numpy array which represents a bunch of RGB values. I'd like to save them as a RGB 565 png image, which I'll then use as a THREE.js texture. How can I do this using Python? Do I just need to write out an appropriate 16-bit greyscale…
nrob
  • 861
  • 1
  • 8
  • 22
3
votes
0 answers

Create an image with pypng

I'm writing a png image to file using PyPng, the file is created but it's all black when viewed.Here is my code: pngImage = numpy.uint16(numpy.zeros((NUM_ROWS, NUM_COLS))) #code that assigns the pixels with open(dataFile + ".png", "wb") as outFile: …
ventsyv
  • 3,316
  • 3
  • 27
  • 49
2
votes
1 answer

With PyPNG, how do I read a PNG with it?

This seems like a dumb question at first--just read the docs!--but I did, and can't figure out how I can read a file, and get an RGB value. Simply, it isn't clear what anything means. Could someone please show me how I could read a file correctly,…
Shiatryx
  • 31
  • 2
2
votes
1 answer

Convert 24-bit PNG files to 8-bit color indexed images with pypng

I'm trying to write a python script that takes in standard 24-bit pngs and converts them to 8-bit pngs for better compression. It looks like pypng can do this but I can't quite figure out how to use it. Image manipulation is a new area for me so…
tsny17
  • 41
  • 1
  • 5
2
votes
3 answers

Why I cannot import a library that is in my pip list?

I have just installed pypng library with sudo -E pip install pypng. I see this library in the list when I execute pip list (the version that I see there is 0.0.18). When I start python (or ipython) session and execute import pypng I…
Roman
  • 124,451
  • 167
  • 349
  • 456
2
votes
1 answer

Save grayscale image as 4 bit png with python

I am looking for a fast way to save a grayscale image as a 4-bit png with python. The images that I have to save are quite big, so saving them takes quite some time. Suppose my image is stored in a numpy-array (dtype=8-bit). With PyPng I can…
Thomas
  • 1,277
  • 1
  • 12
  • 20
2
votes
2 answers

How to make 2d images with PyPNG with 2D Python Lists

So reading the readme, I expected the following code: import png R = 10 G = 255 B = 0 color = [[ (R,G,B), (R,G,B), (R,G,B) ], [ (R,G,B), (R,G,B), (R,G,B) ]] png.from_array(color, 'RGB').save("small_smiley.png") to output a 2x3…
dcheng
  • 1,827
  • 1
  • 11
  • 20
2
votes
2 answers

how to read itertools.imap object from PyPNG's reader

I'm using PyPNG package to read a simple png file. The returned pixels data is an itertools.imap object. How do I read this data. import png, array reader = png.Reader(filename='image.png') w, h, pixels, metadata = reader.read() (877, 615,…
elgnoh
  • 493
  • 5
  • 15
1
vote
1 answer

Pypng: numpy array differs from output PNG file

I'm trying to write a program that creates a png file and paints the outer pixel black. I only need black and white so bitdepth=1 works for my situation. import png import numpy as np MazeHeight = 5 MazeWidth = 7 if __name__ == "__main__": …
Wave
  • 21
  • 2
1
vote
1 answer

How to install png module for python in Anaconda Python3 Environment

I'm trying to set up a Python 3 environment that has access to the png module. When I list the installed packages, I get this: (Python3_Env) me@gimli:~$ conda list # packages in environment at /home/me/anaconda2/envs/Python3_Env: # # Name …
user1245262
  • 6,968
  • 8
  • 50
  • 77
1
vote
1 answer

Store 2D Array in .png format with colours

I wrote this Python Program to create and save a matrix (2D Array) to a .png file. The program compiles and runs without any error. Even the IMAGE.png file is created but the png file won't open. When I try to open it in MSPaint, it says: Cannot…
ArnabC
  • 181
  • 1
  • 3
  • 16
1
2 3