Read and write Netpbm files
===========================
Netpbmfile is a Python library to read and write image files in the Netpbm
or related formats:
- PBM (Portable Bit Map): P1 (text) and P4 (binary)
- PGM (Portable Gray Map): P2 (text) and P5 (binary)
- PPM (Portable Pixel Map): P3 (text) and P6 (binary)
- PNM (Portable Any Map): shorthand for PBM, PGM, and PPM collectively
- PAM (Portable Arbitrary Map): P7, bilevel, gray, and rgb
- PGX (Portable Graymap Signed): PG, signed grayscale
- PFM (Portable Float Map): Pf (gray), PF (rgb), and PF4 (rgba), read-only
- XV thumbnail: P7 332 (rgb332), read-only
The Netpbm formats are specified at https://netpbm.sourceforge.net/doc/.
The PGX format is specified in ITU-T Rec. T.803.
No gamma correction or scaling is performed.
:Author: `Christoph Gohlke <https://www.cgohlke.com>`_
:License: BSD 3-Clause
:Version: 2025.1.1
Quickstart
----------
Install the netpbmfile package and all dependencies from the
`Python Package Index <https://pypi.org/project/netpbmfile/>`_::
python -m pip install -U "netpbmfile[all]"
See `Examples`_ for using the programming interface.
Source code and support are available on
`GitHub <https://github.com/cgohlke/netpbmfile>`_.
Requirements
------------
This revision was tested with the following requirements and dependencies
(other versions may work):
- `CPython <https://www.python.org>`_ 3.10.11, 3.11.9, 3.12.8, 3.13.1 64-bit
- `NumPy <https://pypi.org/project/numpy/>`_ 2.1.3
Revisions
---------
2025.1.1
- Improve type hints.
- Drop support for Python 3.9, support Python 3.13.
2024.5.24
- Fix docstring examples not correctly rendered on GitHub.
2024.4.24
- Support NumPy 2.
2023.8.30
- Fix linting issues.
- Add py.typed marker.
2023.6.15
- Drop support for Python 3.8 and numpy < 1.21 (NEP29).
- Improve type hints.
2023.1.1
- Several breaking changes:
- Rename magicnum to magicnumber (breaking).
- Rename tupltypes to tupltype (breaking).
- Change magicnumber and header properties to str (breaking).
- Replace pam parameter with magicnumber (breaking).
- Move byteorder parameter from NetpbmFile.asarray to NetpbmFile (breaking).
- Fix shape and axes properties for multi-image files.
- Add maxval and tupltype parameters to NetpbmFile.fromdata and imwrite.
- Add option to write comment to PNM and PAM files.
- Support writing PGX and text formats.
- Add Google style docstrings.
- Add unittests.
2022.10.25
- …
Refer to the CHANGES file for older revisions.
Examples
--------
Write a numpy array to a Netpbm file in grayscale binary format:
>>> data = numpy.array([[0, 1], [65534, 65535]], dtype=numpy.uint16)
>>> imwrite('_tmp.pgm', data)
Read the image data from a Netpbm file as numpy array:
>>> image = imread('_tmp.pgm')
>>> numpy.testing.assert_equal(image, data)
Access meta and image data in a Netpbm file:
>>> with NetpbmFile('_tmp.pgm') as pgm:
... pgm.magicnumber
... pgm.axes
... pgm.shape
... pgm.dtype
... pgm.maxval
... pgm.asarray().tolist()
...
'P5'
'YX'
(2, 2)
dtype('>u2')
65535
[[0, 1], [65534, 65535]]
View the image and metadata in the Netpbm file from the command line::
$ python -m netpbmfile _tmp.pgm
Raw data
{
"_id": null,
"home_page": "https://www.cgohlke.com",
"name": "netpbmfile",
"maintainer": null,
"docs_url": null,
"requires_python": ">=3.10",
"maintainer_email": null,
"keywords": null,
"author": "Christoph Gohlke",
"author_email": "cgohlke@cgohlke.com",
"download_url": "https://files.pythonhosted.org/packages/4c/b2/327fdd1d0d0e999f2db3b7f4f48ef424c10abc107881e5a6f96f33b3aecb/netpbmfile-2025.1.1.tar.gz",
"platform": "any",
"description": "Read and write Netpbm files\r\n===========================\r\n\r\nNetpbmfile is a Python library to read and write image files in the Netpbm\r\nor related formats:\r\n\r\n- PBM (Portable Bit Map): P1 (text) and P4 (binary)\r\n- PGM (Portable Gray Map): P2 (text) and P5 (binary)\r\n- PPM (Portable Pixel Map): P3 (text) and P6 (binary)\r\n- PNM (Portable Any Map): shorthand for PBM, PGM, and PPM collectively\r\n- PAM (Portable Arbitrary Map): P7, bilevel, gray, and rgb\r\n- PGX (Portable Graymap Signed): PG, signed grayscale\r\n- PFM (Portable Float Map): Pf (gray), PF (rgb), and PF4 (rgba), read-only\r\n- XV thumbnail: P7 332 (rgb332), read-only\r\n\r\nThe Netpbm formats are specified at https://netpbm.sourceforge.net/doc/.\r\n\r\nThe PGX format is specified in ITU-T Rec. T.803.\r\n\r\nNo gamma correction or scaling is performed.\r\n\r\n:Author: `Christoph Gohlke <https://www.cgohlke.com>`_\r\n:License: BSD 3-Clause\r\n:Version: 2025.1.1\r\n\r\nQuickstart\r\n----------\r\n\r\nInstall the netpbmfile package and all dependencies from the\r\n`Python Package Index <https://pypi.org/project/netpbmfile/>`_::\r\n\r\n python -m pip install -U \"netpbmfile[all]\"\r\n\r\nSee `Examples`_ for using the programming interface.\r\n\r\nSource code and support are available on\r\n`GitHub <https://github.com/cgohlke/netpbmfile>`_.\r\n\r\nRequirements\r\n------------\r\nThis revision was tested with the following requirements and dependencies\r\n(other versions may work):\r\n\r\n- `CPython <https://www.python.org>`_ 3.10.11, 3.11.9, 3.12.8, 3.13.1 64-bit\r\n- `NumPy <https://pypi.org/project/numpy/>`_ 2.1.3\r\n\r\nRevisions\r\n---------\r\n\r\n2025.1.1\r\n\r\n- Improve type hints.\r\n- Drop support for Python 3.9, support Python 3.13.\r\n\r\n2024.5.24\r\n\r\n- Fix docstring examples not correctly rendered on GitHub.\r\n\r\n2024.4.24\r\n\r\n- Support NumPy 2.\r\n\r\n2023.8.30\r\n\r\n- Fix linting issues.\r\n- Add py.typed marker.\r\n\r\n2023.6.15\r\n\r\n- Drop support for Python 3.8 and numpy < 1.21 (NEP29).\r\n- Improve type hints.\r\n\r\n2023.1.1\r\n\r\n- Several breaking changes:\r\n- Rename magicnum to magicnumber (breaking).\r\n- Rename tupltypes to tupltype (breaking).\r\n- Change magicnumber and header properties to str (breaking).\r\n- Replace pam parameter with magicnumber (breaking).\r\n- Move byteorder parameter from NetpbmFile.asarray to NetpbmFile (breaking).\r\n- Fix shape and axes properties for multi-image files.\r\n- Add maxval and tupltype parameters to NetpbmFile.fromdata and imwrite.\r\n- Add option to write comment to PNM and PAM files.\r\n- Support writing PGX and text formats.\r\n- Add Google style docstrings.\r\n- Add unittests.\r\n\r\n2022.10.25\r\n\r\n- \u2026\r\n\r\nRefer to the CHANGES file for older revisions.\r\n\r\nExamples\r\n--------\r\n\r\nWrite a numpy array to a Netpbm file in grayscale binary format:\r\n\r\n>>> data = numpy.array([[0, 1], [65534, 65535]], dtype=numpy.uint16)\r\n>>> imwrite('_tmp.pgm', data)\r\n\r\nRead the image data from a Netpbm file as numpy array:\r\n\r\n>>> image = imread('_tmp.pgm')\r\n>>> numpy.testing.assert_equal(image, data)\r\n\r\nAccess meta and image data in a Netpbm file:\r\n\r\n>>> with NetpbmFile('_tmp.pgm') as pgm:\r\n... pgm.magicnumber\r\n... pgm.axes\r\n... pgm.shape\r\n... pgm.dtype\r\n... pgm.maxval\r\n... pgm.asarray().tolist()\r\n...\r\n'P5'\r\n'YX'\r\n(2, 2)\r\ndtype('>u2')\r\n65535\r\n[[0, 1], [65534, 65535]]\r\n\r\nView the image and metadata in the Netpbm file from the command line::\r\n\r\n $ python -m netpbmfile _tmp.pgm\r\n",
"bugtrack_url": null,
"license": "BSD",
"summary": "Read and write Netpbm files",
"version": "2025.1.1",
"project_urls": {
"Bug Tracker": "https://github.com/cgohlke/netpbmfile/issues",
"Homepage": "https://www.cgohlke.com",
"Source Code": "https://github.com/cgohlke/netpbmfile"
},
"split_keywords": [],
"urls": [
{
"comment_text": "",
"digests": {
"blake2b_256": "f0a0b7c35263a64a8153f366f5de9a6e4a60b9599831bb1a0c0fc8f8538454f5",
"md5": "bdf7a4559005b5592b5f0aad997be118",
"sha256": "b6786735a1d6cb16f2ba3677f0e152cdc635fdec2030b474c7331990f0baa20b"
},
"downloads": -1,
"filename": "netpbmfile-2025.1.1-py3-none-any.whl",
"has_sig": false,
"md5_digest": "bdf7a4559005b5592b5f0aad997be118",
"packagetype": "bdist_wheel",
"python_version": "py3",
"requires_python": ">=3.10",
"size": 14115,
"upload_time": "2025-01-02T02:31:38",
"upload_time_iso_8601": "2025-01-02T02:31:38.585201Z",
"url": "https://files.pythonhosted.org/packages/f0/a0/b7c35263a64a8153f366f5de9a6e4a60b9599831bb1a0c0fc8f8538454f5/netpbmfile-2025.1.1-py3-none-any.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": "",
"digests": {
"blake2b_256": "4cb2327fdd1d0d0e999f2db3b7f4f48ef424c10abc107881e5a6f96f33b3aecb",
"md5": "282a209d68794a3f4df93781dd675c59",
"sha256": "e041e40f4fd5f78fb76e23b917d1015f29663226700370297814ad9ffc339cf1"
},
"downloads": -1,
"filename": "netpbmfile-2025.1.1.tar.gz",
"has_sig": false,
"md5_digest": "282a209d68794a3f4df93781dd675c59",
"packagetype": "sdist",
"python_version": "source",
"requires_python": ">=3.10",
"size": 30150,
"upload_time": "2025-01-02T02:31:50",
"upload_time_iso_8601": "2025-01-02T02:31:50.799848Z",
"url": "https://files.pythonhosted.org/packages/4c/b2/327fdd1d0d0e999f2db3b7f4f48ef424c10abc107881e5a6f96f33b3aecb/netpbmfile-2025.1.1.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2025-01-02 02:31:50",
"github": true,
"gitlab": false,
"bitbucket": false,
"codeberg": false,
"github_user": "cgohlke",
"github_project": "netpbmfile",
"travis_ci": false,
"coveralls": false,
"github_actions": false,
"lcname": "netpbmfile"
}