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.7(2mo ago)0575—0%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 1mo ago

READMEChangelog (10)Dependencies (10)Versions (56)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.

#### 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

49

—

FairBetter than 95% of packages

Maintenance86

Actively maintained with recent releases

Popularity17

Limited adoption so far

Community11

Small or concentrated contributor base

Maturity69

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

Recently: every ~2 days

Total

50

Last Release

68d 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 (138 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

[pocketmine/pocketmine-mp

A server software for Minecraft: Bedrock Edition written in PHP

3.5k74.6k86](/packages/pocketmine-pocketmine-mp)[civicrm/civicrm-core

Open source constituent relationship management for non-profits, NGOs and advocacy organizations.

728272.9k20](/packages/civicrm-civicrm-core)[friendsoftypo3/content-blocks

TYPO3 CMS Content Blocks - Content Types API | Define reusable components via YAML

96374.6k23](/packages/friendsoftypo3-content-blocks)[data-uri/data-uri

PHP DataURI component

60627.5k4](/packages/data-uri-data-uri)[codefog/contao-haste

haste extension for Contao Open Source CMS

42650.8k139](/packages/codefog-contao-haste)[shyim/danger-php

Port of danger to PHP

8544.9k](/packages/shyim-danger-php)

PHPackages © 2026

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