PHPackages                             pateon/steganography - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Image &amp; Media](/categories/media)
4. /
5. pateon/steganography

ActiveLibrary[Image &amp; Media](/categories/media)

pateon/steganography
====================

Invisible anti-counterfeiting for images using LSB Steganography (PHP 8.5+). Supports Imagick and GD.

v1.1(4mo ago)07MITPHPPHP &gt;=8.5.0

Since Dec 28Pushed 4mo agoCompare

[ Source](https://github.com/pateon/steganography)[ Packagist](https://packagist.org/packages/pateon/steganography)[ RSS](/packages/pateon-steganography/feed)WikiDiscussions main Synced 1mo ago

READMEChangelogDependencies (1)Versions (3)Used By (0)

Steganography
=============

[](#steganography)

[![PHP Version](https://camo.githubusercontent.com/d34bb3815837b58c993746acbcf32acec642413e9ce88370a4379cd823168939/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f7068702d253345253344382e352d3838393242462e737667)](https://php.net/)[![License: MIT](https://camo.githubusercontent.com/fdf2982b9f5d7489dcf44570e714e3a15fce6253e0cc6b5aa61a075aac2ff71b/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f4c6963656e73652d4d49542d79656c6c6f772e737667)](https://opensource.org/licenses/MIT)[![Latest Version](https://camo.githubusercontent.com/306d3ab05eb5ed150fe6e35d96747a5578d62a1f407243220fd96602008515e5/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f762f7461672f706174656f6e2f73746567616e6f6772617068793f6c6162656c3d76657273696f6e)](https://github.com/pateon/steganography)

A PHP 8.5+ library for invisible anti-counterfeiting of images using LSB (Least Significant Bit) Steganography. This library hides a secret message inside an image file, invisible to the human eye.

Features
--------

[](#features)

- ✅ **Invisible**: Modifies only the Least Significant Bits (LSB) of RGB pixel values
- ✅ **Compression**: Compresses messages using Zlib before embedding
- ✅ **Unicode Support**: Full support for UTF-8, including CJK characters and emoji
- ✅ **Dual Driver Support**: Prioritizes `Imagick`, falls back to `GD` automatically
- ✅ **Format Support**: Reads JPG, PNG, GIF, WebP, BMP as source images
- ✅ **Lossless Output**: Always outputs as PNG to preserve hidden data
- ✅ **PHP 8.5+**: Uses modern PHP features (typed constants, readonly properties, match expressions)
- ✅ **Composer Ready**: PSR-4 autoloading, ready for integration

Requirements
------------

[](#requirements)

- PHP &gt;= 8.5
- `ext-zlib` (for compression)
- `ext-imagick` (recommended) **OR** `ext-gd` (at least one is required)

Installation
------------

[](#installation)

```
composer require pateon/steganography
```

Usage
-----

[](#usage)

### Basic Usage

[](#basic-usage)

```
use Steganography\Processor;

$processor = new Processor();

// Encode a message into an image
$image = $processor->encode('source.jpg', 'This is my secret message! 秘密訊息');
$image->save('output.png'); // MUST save as PNG (lossless)

// Decode the message from the image
$message = $processor->decode('output.png');
echo $message; // "This is my secret message! 秘密訊息"
```

### Force Specific Adapter

[](#force-specific-adapter)

```
$processor = new Processor();

// Force GD
$processor->setPreferredAdapter('gd');

// Force Imagick
$processor->setPreferredAdapter('imagick');
```

### Calculate Maximum Message Size

[](#calculate-maximum-message-size)

```
$processor = new Processor();
$maxBytes = $processor->calculateMaxMessageSize('source.jpg');
echo "Max message size: ~{$maxBytes} bytes";
```

### Custom Compressor

[](#custom-compressor)

```
use Steganography\Processor;
use Steganography\Compressor\ZlibCompressor;

$processor = new Processor(
    compressor: new ZlibCompressor(level: 9) // Maximum compression
);
```

⚠️ Important Notes
------------------

[](#️-important-notes)

1. **Output Format**: Always save encoded images as **PNG**. JPG compression is lossy and will destroy the hidden data.
2. **Source Format**: JPG, PNG, GIF, WebP, and BMP are supported as source images.
3. **Image Size**: Larger images can store more data. Use `calculateMaxMessageSize()` to check capacity.
4. **Imagick vs GD**: Imagick is preferred for better performance. GD is used as fallback.

Architecture
------------

[](#architecture)

```
src/
├── Processor.php              # Main entry point
├── Compressor/
│   ├── CompressorInterface.php
│   └── ZlibCompressor.php     # Zlib compression
├── Encoder/
│   ├── EncoderInterface.php
│   └── DefaultEncoder.php     # Base64 + Binary encoding
├── Exception/
│   ├── SteganographyException.php
│   ├── ImageTooSmallException.php
│   └── DecodeException.php
├── Image/
│   ├── Image.php              # LSB steganography logic
│   ├── Color.php              # RGBA color DTO
│   └── Adapter/
│       ├── ImageAdapterInterface.php
│       ├── GdAdapter.php      # GD implementation
│       └── ImagickAdapter.php # Imagick implementation
└── Iterator/
    ├── BinaryIterator.php     # Binary data iterator
    └── RectIterator.php       # Pixel coordinate iterator

```

How It Works
------------

[](#how-it-works)

1. **Compression**: The message is compressed using Zlib
2. **Encoding**: Compressed data is Base64 encoded, then converted to binary (0s and 1s)
3. **Embedding**: Each pixel's RGB values have their LSB modified to store 3 bits (1 per channel)
4. **Header**: A 48-bit length header is prepended to know how much data to read when decoding

License
-------

[](#license)

MIT License - see [LICENSE](LICENSE) file

###  Health Score

36

—

LowBetter than 82% of packages

Maintenance76

Regular maintenance activity

Popularity4

Limited adoption so far

Community2

Small or concentrated contributor base

Maturity53

Maturing project, gaining track record

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~0 days

Total

2

Last Release

132d ago

PHP version history (2 changes)v1.0PHP &gt;=8.2

v1.1PHP &gt;=8.5.0

### Community

Maintainers

![](https://www.gravatar.com/avatar/96903a9bc6e768754ab558ba484a69a1deea887e7a3821ec9941e0424d71add0?d=identicon)[stu89064](/maintainers/stu89064)

---

Tags

imagegdimagickwatermarksteganographylsbanti-counterfeiting

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/pateon-steganography/health.svg)

```
[![Health](https://phpackages.com/badges/pateon-steganography/health.svg)](https://phpackages.com/packages/pateon-steganography)
```

###  Alternatives

[intervention/image

PHP Image Processing

14.3k194.3M2.2k](/packages/intervention-image)[intervention/image-laravel

Laravel Integration of Intervention Image

1496.5M100](/packages/intervention-image-laravel)[folklore/image

Image manipulation library for Laravel 5 based on Imagine and inspired by Croppa for easy url based manipulation

270248.2k5](/packages/folklore-image)[pavlista/nette-palette

Palette support for Nette Framework and Latte template engine

1657.4k](/packages/pavlista-nette-palette)[intervention/image-symfony

Symfony Integration of Intervention Image

1066.8k](/packages/intervention-image-symfony)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
