PHPackages                             1tomany/data-uri - 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. [Utility &amp; Helpers](/categories/utility)
4. /
5. 1tomany/data-uri

ActiveLibrary[Utility &amp; Helpers](/categories/utility)

1tomany/data-uri
================

A simple, low dependency library to parse and decode data URIs defined in RFC 2397

v7.0.1(2w ago)01.5k↑21.9%1MITPHPPHP &gt;=8.4

Since Dec 17Pushed 2mo ago2 watchersCompare

[ Source](https://github.com/1tomany/data-uri)[ Packagist](https://packagist.org/packages/1tomany/data-uri)[ RSS](/packages/1tomany-data-uri/feed)WikiDiscussions master Synced 2w ago

READMEChangelog (10)Dependencies (26)Versions (63)Used By (1)

Data URI Parser for PHP
=======================

[](#data-uri-parser-for-php)

This simple library allows you to easily convert a wide variety of data into a temporary file represented by a lightweight immutable value object.

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

[](#installation)

```
composer require 1tomany/data-uri

```

API Overview
------------

[](#api-overview)

The three methods exposed by this library are:

- `OneToMany\DataUri\DataDecoder::decode()`
- `OneToMany\DataUri\DataDecoder::decodeBase64()`
- `OneToMany\DataUri\DataDecoder::decodeText()`

Each method returns a `OneToMany\DataUri\Record\TemporaryFile` value object which implements the interface `OneToMany\DataUri\Contract\Record\TemporaryFileInterface`. By default, the `TemporaryFile` object will delete any filesystem resources it knows about when it is explicitly destructed or garbage collected.

The `DataDecoder::decode()` method is the most versatile as it allows for a wide variety of inputs:

- A data URI defined in [RFC2397](https://www.rfc-editor.org/rfc/rfc2397.html)
- A file from an accessible filesystem
- A public HTTP or HTTPS URL

### `DataDecoder::decode()`

[](#datadecoderdecode)

The `DataDecoder::decode()` method has the following arguments:

- `mixed $data` The data, file, or URL to decode.
- `string|FileType|null $type = null` The MIME type of the temporary file. If empty, the type will be determined using either the file's extension or the `mime_content_type()` function. You may want to explicitly provide this argument when the file can be multiple types. For example, `mime_content_type()` may return `text/plain` for Markdown files, which is correct, however, you may wish to use the more specific MIME type `text/markdown`.
- `string|null $name = null` The name for the temporary file. This is useful for handling file uploads where the original filename is preferred over the random one PHP assigns. A randomly generated name will be used if this is empty and a name cannot be resolved.

#### Inside `DataDecoder::decode()`

[](#inside-datadecoderdecode)

Under the hood, `DataDecoder::decode()` uses the `fopen()` and `stream_get_contents()` functions, which means the data passed to it can be any [stream](https://www.php.net/manual/en/wrappers.php) that PHP supports.

### `DataDecoder::decodeBase64()`

[](#datadecoderdecodebase64)

This method is to be used when the data is known to be base64 encoded but NOT encoded as a data URI.

The `DataDecoder::decodeBase64()` method has the following parameters:

- `string $data` The base64 encoded string.
- `string|FileType $type` The MIME type of the data.
- `string|null $name = null` See `DataDecoder::decode()`.

### `DataDecoder::decodeText()`

[](#datadecoderdecodetext)

This method is to be used when the data is known to be plaintext.

The `DataDecoder::decodeText()` method has the following arguments:

- `string $text` The plaintext string.
- `string|FileType $type = FileType::Txt` The MIME type of the text.
- `string|null $name = null` See `DataDecoder::decode()`.

Examples
--------

[](#examples)

Run and inspect the [`decode.php`](https://github.com/1tomany/data-uri/blob/master/examples/decode.php) file for examples on how to use the `DataDecoder::decode()` method.

```
php examples/decode.php [--all]
```

Credits
-------

[](#credits)

- [Vic Cherubini](https://github.com/viccherubini), [1:N Labs, LLC](https://1tomany.com)

License
-------

[](#license)

The MIT License

###  Health Score

52

—

FairBetter than 96% of packages

Maintenance90

Actively maintained with recent releases

Popularity21

Limited adoption so far

Community13

Small or concentrated contributor base

Maturity71

Established project with proven stability

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

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 ~11 days

Recently: every ~24 days

Total

55

Last Release

18d ago

Major Versions

v2.6.0 → v3.0.02025-04-10

v3.0.0 → v4.0.02025-04-22

v4.5.1 → v5.0.02025-10-15

v5.0.5 → v6.0.02026-01-27

v6.0.10 → v7.0.02026-07-30

PHP version history (2 changes)v1.0.0PHP &gt;=8.3

v1.5.2PHP &gt;=8.4

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/60762?v=4)[Vic Cherubini](/maintainers/viccherubini)[@viccherubini](https://github.com/viccherubini)

---

Top Contributors

[![viccherubini](https://avatars.githubusercontent.com/u/60762?v=4)](https://github.com/viccherubini "viccherubini (142 commits)")

---

Tags

data-urirfc 2397dataURIrfc23972397

###  Code Quality

TestsPHPUnit

Static AnalysisPHPStan

Code StylePHP CS Fixer

Type Coverage Yes

### Embed Badge

![Health badge](/badges/1tomany-data-uri/health.svg)

```
[![Health](https://phpackages.com/badges/1tomany-data-uri/health.svg)](https://phpackages.com/packages/1tomany-data-uri)
```

###  Alternatives

[composer/composer

Composer helps you declare, manage and install dependencies of PHP projects. It ensures you have the right stack everywhere.

29.5k199.6M3.4k](/packages/composer-composer)[aws/aws-sdk-php

AWS SDK for PHP - Use Amazon Web Services in your PHP project

6.2k555.0M2.8k](/packages/aws-aws-sdk-php)[symfony/config

Helps you find, load, combine, autofill and validate configuration values of any kind

4.3k488.4M9.3k](/packages/symfony-config)[friendsofphp/php-cs-fixer

A tool to automatically fix PHP code style

13.5k257.0M28.0k](/packages/friendsofphp-php-cs-fixer)[easycorp/easyadmin-bundle

Admin generator for Symfony applications

4.3k18.3M430](/packages/easycorp-easyadmin-bundle)[symfony/asset-mapper

Maps directories of assets &amp; makes them available in a public directory with versioned filenames.

1669.5M285](/packages/symfony-asset-mapper)

PHPackages © 2026

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