Skip to main content

pigsqueeze

CircleCI Downloads

A library to write and read arbitrary data to and from image files. You probably already know why you need it.

pigsuqeeze is a command line tool as well as a Python library for easily writing arbitrary data to (and later retrieving it from) image files. Currently only JPEG and PNG are supported, but I'm open to add support for more file formats if they support this.

For JPEG's, pigsqueeze stores binary data in one or more chunks of app-specific data segments as enabled by the JPEG specification. pigsqueeze automatically handles splitting large blobs of data across multiple chunks, since the limit per chunk is ~65KB. pigsqueeze's method allows for payload sizes of up ot ~15MB per segment. Multiple unused segments are available, so there is a theoretical limit of 135MB per image, which is probably plenty. If you need more, you should probably look at a different solution to your problem.

For PNG's, data is stored in out-of-spec chunks, which each have a limit of ~2GB. Because this is plenty large, pigsqueeze does not support chunk splitting for this format.

Installation

pigsuqeeze can be installed via pip:

$ pip install pigsqueeze

Usage

Usage: psz read-jpg [OPTIONS] INPUT_IMAGE OUTPUT_FILE

Options:
  -s, --segment INTEGER  [required]
  -i, --identifier TEXT  [required]
  --help                 Show this message and exit.
Usage: psz write-jpg [OPTIONS] INPUT_IMAGE DATA OUTPUT_FILE

Options:
  -s, --segment INTEGER  [required]
  -i, --identifier TEXT  [required]
  --help                 Show this message and exit.
Usage: psz read-png [OPTIONS] INPUT_IMAGE OUTPUT_FILE

Options:
  -c, --chunk TEXT       [required]
  -i, --identifier TEXT  [required]
  --help                 Show this message and exit.
Usage: psz write-png [OPTIONS] INPUT_IMAGE DATA OUTPUT_FILE

Options:
  -c, --chunk TEXT       [required]
  -i, --identifier TEXT  [required]
  --help                 Show this message and exit.

As a Python library:

from pigsqueeze import load_image

# Write some text to App segment 4 with identifier PSZ
image = load_image("path/to/image.jpg")
image.write(4, "PSZ", b"Some bytes to save in the file.")
image.save("path/to/output.jpg")

# Retrieve the text from the modified image file
image = load_image("path/to/output.jpg")
result = image.read(4, "PSZ")

Usage Notes

JPEG

When adding data, a segment number needs to be specified. Available segment numbers are:

[4, 5, 6, 7, 8, 9, 10, 11, 15]

PNG

When adding data, a chunk name needs to be specified. The name must be 4 characters long. The first letter must be lowercase. It can not be any of the following segment names:

  • IHDR
  • PLTE
  • IDAT
  • IEND
  • tRNS
  • cHRM
  • gAMA
  • iCCP
  • sBIT
  • sRGB
  • iTXt
  • tEXt
  • zTXt
  • bKGD
  • hIST
  • pHYs
  • sPLT
  • tIME

Metadata

Release files for pigsqueeze 2.0.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for pigsqueeze 2.0.1
File Size Uploaded
pigsqueeze-2.0.1.tar.gz 6.1 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for pigsqueeze 2.0.1
File Interpreter ABI Platform
pigsqueeze-2.0.1-py3-none-any.whl Python 3 none any Details

Total release size: 12.7 kB

Release files / pigsqueeze-2.0.1.tar.gz

Download URL pigsqueeze-2.0.1.tar.gz
Size 6.1 kB
Tags Source
SHA-256 checksum
How to use checksums
4f9bf33448de368b256d264833c5f548eecbb5ad7ae5ccfa31c030e535f66397
BLAKE2b-256 checksum
How to use checksums
feb5c7dd5d7fd0b71c32febea45def5d3d019674cd2d8911ed9471f92dee9fe4
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/1.1.4 CPython/3.9.1 Linux/4.15.0-1092-aws

Release files / pigsqueeze-2.0.1-py3-none-any.whl

Download URL pigsqueeze-2.0.1-py3-none-any.whl
Size 6.6 kB
Tags Python 3
SHA-256 checksum
How to use checksums
8a343db7f56b02141c1f2fdabbaa4c64826cd0bbb054f621ef5b4ddeae6125a3
BLAKE2b-256 checksum
How to use checksums
772aca4565855f15c936d69bdbaf10036b2665c2ddc2df3bcd34d3548bc91b51
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/1.1.4 CPython/3.9.1 Linux/4.15.0-1092-aws

Release history Release notifications | RSS feed

This release

2.0.1 This release

2 release files

2.0.0

2 release files

1.0.0

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page