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

v6.0.9(1mo ago)0813↓23.3%1MITPHPPHP &gt;=8.4

Since Dec 17Pushed 1mo 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 yesterday

READMEChangelog (10)Dependencies (20)Versions (59)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 an object that implements the `OneToMany\DataUri\Contract\Record\DataUriInterface` interface. In this implementation, the value object will automatically delete the file it represents when it is 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 public HTTP or HTTPS URL
- A readable file

### `DataDecoder::decode()`

[](#datadecoderdecode)

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

- `mixed $data` The data to decode
- `?string $name` The display name for the temporary file. This is useful for handling file uploads where the original filename is preferred over the random name PHP assigns. A randomly generated name will be used if this is empty and a name cannot be resolved. This is `null` by default.
- `string|Type|null $type` The MIME type of the temporary file. If empty or `null` (the default value), the MIME type (or format) will be determined using the `mime_content_type()` function. This is handy 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`.

#### 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 $format` The format of the data represented as a MIME type
- `?string $name` 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 $name` See `DataDecoder::decode()`. The extension `.txt` will be appended to the `$name` if the value provided does not already use it.

Examples
--------

[](#examples)

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

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

Maintenance94

Actively maintained with recent releases

Popularity18

Limited adoption so far

Community12

Small or concentrated contributor base

Maturity70

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

Recently: every ~22 days

Total

52

Last Release

30d ago

Major Versions

v1.6.0 → v2.0.02025-03-29

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

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.5k196.2M3.1k](/packages/composer-composer)[aws/aws-sdk-php

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

6.3k543.5M2.6k](/packages/aws-aws-sdk-php)[symfony/config

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

4.3k479.6M8.4k](/packages/symfony-config)[friendsofphp/php-cs-fixer

A tool to automatically fix PHP code style

13.5k251.2M25.2k](/packages/friendsofphp-php-cs-fixer)[symfony/asset-mapper

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

1678.8M237](/packages/symfony-asset-mapper)[pocketmine/pocketmine-mp

A server software for Minecraft: Bedrock Edition written in PHP

3.5k78.3k91](/packages/pocketmine-pocketmine-mp)

PHPackages © 2026

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