Skip to main content

XPM image file loader for Python (to numpy ndarray or PIL) native C .pyd

Project description

XPM image file loader for Python (to numpy ndarray or PIL) native C .pyd

How to use

from pyxpm import xpm
import numpy as np
import matplotlib.pyplot as plt
# import matplotlib.image as mpimg
from scipy import misc
from PIL import Image

fig = plt.figure()
axis = [fig.add_subplot(211 + _) for _ in range(2)]
s = open('/tmp/testdata.xpm', 'rb').read()
nda = xpm.XPM(s) # as ndarray (dtype=np.uint8) BGR(A)
r, c, m = nda.shape
img = Image.frombuffer('RGBA', (c, r), nda, 'raw', 'BGRA', 0, 1)
img.show() # PIL.Image
bm = np.array(img) # RGB(A)
axis[0].imshow(bm)
misc.imsave('/tmp/testdata_0.gif', np.uint8(bm))
misc.imsave('/tmp/testdata_1.gif', misc.bytescale(bm, cmin=0, cmax=255))
im = misc.toimage(bm, cmin=0, cmax=255) # same as PIL.Image
im.save('/tmp/testdata.png')
axis[1].imshow(im)
plt.show()

License

MIT License

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

pyxpm-1.0.1.tar.gz (15.4 kB view details)

Uploaded Source

File details

Details for the file pyxpm-1.0.1.tar.gz.

File metadata

  • Download URL: pyxpm-1.0.1.tar.gz
  • Upload date:
  • Size: 15.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No

File hashes

Hashes for pyxpm-1.0.1.tar.gz
Algorithm Hash digest
SHA256 0550002df3b9cc9cb008156d06a3377c2c53f4470dac91c13f3dbc3213c30fc4
MD5 7a43d621d6c15095c6a272d989a3e3db
BLAKE2b-256 2c412d4a935e088269d26f827a852e9c69da4648a12d6fa5e299b63975b6af80

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page