PHPackages                             tourze/blind-watermark - 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. tourze/blind-watermark

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

tourze/blind-watermark
======================

数字图像盲水印嵌入和提取库，支持图像变换和攻击检测

0.0.1(5mo ago)10MITPHPCI passing

Since Nov 16Pushed 5mo ago2 watchersCompare

[ Source](https://github.com/tourze/blind-watermark)[ Packagist](https://packagist.org/packages/tourze/blind-watermark)[ RSS](/packages/tourze-blind-watermark/feed)WikiDiscussions master Synced 1mo ago

READMEChangelog (1)Dependencies (4)Versions (2)Used By (0)

Blind Watermark
===============

[](#blind-watermark)

[English](README.md) | [中文](README.zh-CN.md)

\[[![Latest Version](https://camo.githubusercontent.com/3153896bb4a3e9f1fb7e3b5d4d8f75d8848bbacfd0723e9721ad0c1c09b5707d/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f746f75727a652f626c696e642d77617465726d61726b2e7376673f7374796c653d666c61742d737175617265)](https://camo.githubusercontent.com/3153896bb4a3e9f1fb7e3b5d4d8f75d8848bbacfd0723e9721ad0c1c09b5707d/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f746f75727a652f626c696e642d77617465726d61726b2e7376673f7374796c653d666c61742d737175617265)\] () \[[![Total Downloads](https://camo.githubusercontent.com/ed9ea8acefc0a6cce8b891f1560de725824691553b7e64c915d69c80d31a48b0/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f746f75727a652f626c696e642d77617465726d61726b2e7376673f7374796c653d666c61742d737175617265)](https://camo.githubusercontent.com/ed9ea8acefc0a6cce8b891f1560de725824691553b7e64c915d69c80d31a48b0/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f746f75727a652f626c696e642d77617465726d61726b2e7376673f7374796c653d666c61742d737175617265)\] ()
\[[![PHP Version](https://camo.githubusercontent.com/7a11c416f3e555a1055d94c34319df03fa9a3cf7d8c4b8dcd7c7292aade79edd/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f7068702d762f746f75727a652f626c696e642d77617465726d61726b2e7376673f7374796c653d666c61742d737175617265)](https://camo.githubusercontent.com/7a11c416f3e555a1055d94c34319df03fa9a3cf7d8c4b8dcd7c7292aade79edd/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f7068702d762f746f75727a652f626c696e642d77617465726d61726b2e7376673f7374796c653d666c61742d737175617265)\] () \[[![License](https://camo.githubusercontent.com/467854f9496820dc8694318792f4a4cd7519f420a0da70181024502af27a0d40/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f6c2f746f75727a652f626c696e642d77617465726d61726b2e7376673f7374796c653d666c61742d737175617265)](https://camo.githubusercontent.com/467854f9496820dc8694318792f4a4cd7519f420a0da70181024502af27a0d40/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f6c2f746f75727a652f626c696e642d77617465726d61726b2e7376673f7374796c653d666c61742d737175617265)\] ()
\[[![Build Status](https://camo.githubusercontent.com/38afb7500cc9fcd41a2a0400319f6c7541082f3978e2f28b1e47f04f5a7baa48/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f616374696f6e732f776f726b666c6f772f7374617475732f746f75727a652f6d6f6e6f7265706f2f63692e796d6c3f7374796c653d666c61742d737175617265)](https://camo.githubusercontent.com/38afb7500cc9fcd41a2a0400319f6c7541082f3978e2f28b1e47f04f5a7baa48/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f616374696f6e732f776f726b666c6f772f7374617475732f746f75727a652f6d6f6e6f7265706f2f63692e796d6c3f7374796c653d666c61742d737175617265)\] () \[[![Code Coverage](https://camo.githubusercontent.com/ac8c8ca24a23c6a1e2dd761d3344a076bc41eb5f40877e97238f4ee77d209037/68747470733a2f2f696d672e736869656c64732e696f2f636f6465636f762f632f6769746875622f746f75727a652f6d6f6e6f7265706f3f7374796c653d666c61742d737175617265)](https://camo.githubusercontent.com/ac8c8ca24a23c6a1e2dd761d3344a076bc41eb5f40877e97238f4ee77d209037/68747470733a2f2f696d672e736869656c64732e696f2f636f6465636f762f632f6769746875622f746f75727a652f6d6f6e6f7265706f3f7374796c653d666c61742d737175617265)\] ()

A PHP implementation of blind watermarking technology that allows embedding invisible text watermarks into images using DCT (Discrete Cosine Transform).

Table of Contents
-----------------

[](#table-of-contents)

- [Requirements](#requirements)
- [Features](#features)
- [Installation](#installation)
- [Quick Start](#quick-start)
- [Advanced Usage](#advanced-usage)
- [Command Line Usage](#command-line-usage)
- [Configuration Parameters](#configuration-parameters)
- [Anti-Attack Features](#anti-attack-features)
- [Exception Handling](#exception-handling)
- [Technical Details](#technical-details)
- [Limitations](#limitations)
- [Performance Considerations](#performance-considerations)
- [Security](#security)
- [Contributing](#contributing)
- [Changelog](#changelog)
- [License](#license)

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

[](#requirements)

- PHP 8.1 or higher
- GD extension

Features
--------

[](#features)

- **Invisible Watermarks**: Embeds text watermarks that are imperceptible to human eyes
- **Blind Extraction**: Extract watermarks without requiring the original image
- **DCT-based Technology**: Uses frequency domain embedding for robust watermark placement
- **Anti-attack Features**:
    - Symmetric embedding for flip resistance
    - Multi-point embedding for enhanced robustness
    - Geometric transformation correction
- **Image Format Support**: Supports JPEG and PNG formats
- **Simple API**: Easy-to-use interface for watermark embedding and extraction

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

[](#installation)

Install via Composer:

```
composer require tourze/blind-watermark
```

Quick Start
-----------

[](#quick-start)

### Basic Usage

[](#basic-usage)

#### Embed Watermark

[](#embed-watermark)

```
use Tourze\BlindWatermark\BlindWatermark;

$watermark = new BlindWatermark();
$watermark->embedTextToImage(
    'input.jpg',           // Source image path
    'Copyright 2024',      // Text to embed
    'watermarked.jpg'      // Output image path
);
```

#### Extract Watermark

[](#extract-watermark)

```
use Tourze\BlindWatermark\BlindWatermark;

$watermark = new BlindWatermark();
$text = $watermark->extractTextFromImage('watermarked.jpg');
echo "Extracted text: " . $text;
```

Advanced Usage
--------------

[](#advanced-usage)

### Advanced Configuration

[](#advanced-configuration)

```
use Tourze\BlindWatermark\BlindWatermark;

$watermark = new BlindWatermark();

// Configure watermark parameters
$watermark->setAlpha(90.0)              // Set watermark strength (default: 36.0)
    ->setBlockSize(8)                   // Set DCT block size (default: 8)
    ->setPosition([3, 4])               // Set embedding position in DCT coefficients
    ->enableSymmetricEmbedding()        // Enable flip resistance
    ->enableMultiPointEmbedding()       // Enable enhanced robustness
    ->enableGeometricCorrection();      // Enable geometric transformation correction

// Embed watermark
$watermark->embedTextToImage(
    'source.jpg',
    'Secret Message',
    'output.jpg',
    'jpeg',     // Output format (optional, default: jpeg)
    90          // Output quality (optional, default: 90)
);
```

### Step-by-Step API

[](#step-by-step-api)

```
use Tourze\BlindWatermark\BlindWatermark;

$watermark = new BlindWatermark();

// Load image
$watermark->loadImage('source.jpg');

// Configure and embed
$watermark->setAlpha(50.0)
    ->embedText('My Watermark');

// Save result
$watermark->saveImage('output.jpg', 'jpeg', 95);

// Extract from saved image
$watermark->loadImage('output.jpg');
$extractedText = $watermark->extractText();
```

Command Line Usage
------------------

[](#command-line-usage)

The package includes command-line scripts for easy watermark operations:

### Embed watermark

[](#embed-watermark-1)

```
php examples/embed_text.php
```

### Extract watermark

[](#extract-watermark-1)

```
php examples/extract_text.php
```

Configuration Parameters
------------------------

[](#configuration-parameters)

ParameterDescriptionDefaultRange`alpha`Watermark strength coefficient36.00.1 - 100.0`blockSize`DCT block size84, 8, 16`position`Embedding position in DCT matrix\[3, 4\]\[0-7, 0-7\]Anti-Attack Features
--------------------

[](#anti-attack-features)

### Symmetric Embedding

[](#symmetric-embedding)

Protects against horizontal and vertical flipping by embedding watermark information symmetrically.

```
$watermark->enableSymmetricEmbedding();
```

### Multi-Point Embedding

[](#multi-point-embedding)

Enhances robustness by embedding the same watermark bit at multiple positions.

```
$watermark->enableMultiPointEmbedding();
```

### Geometric Correction

[](#geometric-correction)

Automatically detects and corrects geometric transformations before extraction.

```
$watermark->enableGeometricCorrection();
```

Exception Handling
------------------

[](#exception-handling)

All errors are thrown as `BlindWatermarkException`:

```
use Tourze\BlindWatermark\BlindWatermark;
use Tourze\BlindWatermark\Exception\BlindWatermarkException;

try {
    $watermark = new BlindWatermark();
    $watermark->embedTextToImage('input.jpg', 'watermark', 'output.jpg');
} catch (BlindWatermarkException $e) {
    echo "Error: " . $e->getMessage();
}
```

Technical Details
-----------------

[](#technical-details)

The library implements blind watermarking using DCT (Discrete Cosine Transform):

1. **Embedding Process**:

    - Decomposes the image into RGB channels
    - Applies 8x8 block DCT transformation to the blue channel
    - Embeds watermark bits in mid-frequency DCT coefficients
    - Reconstructs the image using inverse DCT
2. **Extraction Process**:

    - Performs the same DCT transformation on the watermarked image
    - Extracts embedded bits from the designated DCT coefficients
    - Reconstructs the original text from the binary data

Limitations
-----------

[](#limitations)

- Text watermarks only (image watermarks not supported)
- Watermark capacity depends on image size
- Rotation support limited to 90-degree increments
- Requires GD extension (ImageMagick not supported)

Performance Considerations
--------------------------

[](#performance-considerations)

- Larger `blockSize` values reduce processing time but decrease watermark capacity
- Higher `alpha` values increase watermark robustness but may affect image quality
- Enabling anti-attack features increases processing time

Security
--------

[](#security)

### Security Considerations

[](#security-considerations)

- **Watermark Detection**: While watermarks are invisible to human eyes, they can potentially be detected by specialized analysis tools
- **Text Limitations**: Avoid embedding sensitive information as the extraction algorithm may be reverse-engineered
- **File Integrity**: Always verify image integrity before watermark extraction
- **Parameter Protection**: Keep watermark parameters (alpha, position) confidential for enhanced security

### Best Practices

[](#best-practices)

1. Use strong, unique parameters for each watermarking session
2. Implement additional encryption for sensitive watermark content
3. Regularly test watermark robustness against common image processing operations
4. Monitor for potential watermark removal attempts

Contributing
------------

[](#contributing)

We welcome contributions! Please follow these guidelines:

### Reporting Issues

[](#reporting-issues)

- Use the GitHub issue tracker to report bugs
- Provide clear reproduction steps
- Include PHP version and system information
- Attach sample images if applicable

### Submitting Pull Requests

[](#submitting-pull-requests)

1. Fork the repository
2. Create a feature branch (`git checkout -b feature/amazing-feature`)
3. Make your changes
4. Run tests: `./vendor/bin/phpunit packages/blind-watermark/tests`
5. Run static analysis: `php -d memory_limit=2G ./vendor/bin/phpstan analyse packages/blind-watermark`
6. Commit your changes (`git commit -m 'Add amazing feature'`)
7. Push to the branch (`git push origin feature/amazing-feature`)
8. Open a Pull Request

### Code Style

[](#code-style)

- Follow PSR-12 coding standards
- Use PHP 8.1+ features and type declarations
- Add PHPDoc comments for public methods
- Write meaningful variable and method names

### Testing Requirements

[](#testing-requirements)

- Write tests for new features
- Ensure all tests pass
- Maintain or improve code coverage
- Test edge cases and error conditions

Changelog
---------

[](#changelog)

### \[Unreleased\]

[](#unreleased)

- Initial release
- Basic watermark embedding and extraction
- DCT-based implementation
- Anti-attack features (flip, rotation resistance)
- Command line interface
- Comprehensive test suite

License
-------

[](#license)

This package is open-sourced software licensed under the MIT license.

###  Health Score

26

—

LowBetter than 43% of packages

Maintenance70

Regular maintenance activity

Popularity2

Limited adoption so far

Community4

Small or concentrated contributor base

Maturity25

Early-stage or recently created project

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

Unknown

Total

1

Last Release

175d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/e354fdb316da535dfa8ba2e9193a473c403b6bc6fb9170778d1dc50e304c6e9d?d=identicon)[tourze](/maintainers/tourze)

###  Code Quality

TestsPHPUnit

Static AnalysisPHPStan

Type Coverage Yes

### Embed Badge

![Health badge](/badges/tourze-blind-watermark/health.svg)

```
[![Health](https://phpackages.com/badges/tourze-blind-watermark/health.svg)](https://phpackages.com/packages/tourze-blind-watermark)
```

###  Alternatives

[spatie/image-optimizer

Easily optimize images using PHP

2.9k71.3M109](/packages/spatie-image-optimizer)[danog/madelineproto

Async PHP client API for the telegram MTProto protocol.

3.4k855.0k18](/packages/danog-madelineproto)[ps/image-optimizer

Image optimization / compression library. This library is able to optimize png, jpg and gif files in very easy and handy way. It uses optipng, pngquant, pngcrush, pngout, gifsicle, jpegoptim and jpegtran tools.

9341.7M25](/packages/ps-image-optimizer)[yireo/magento2-next-gen-images

Magento 2 module to add NextGen images support to the Magento frontend

471.1M2](/packages/yireo-magento2-next-gen-images)[godruoyi/ocr

The Best Image Ocr SDK For BAT.

19314.7k1](/packages/godruoyi-ocr)[bravo3/image-manager

A PHP 5.4 library to control dynamic image assets in a cloud environment

178.1k](/packages/bravo3-image-manager)

PHPackages © 2026

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