PHPackages                             rbraunm/class\_dicom - 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. rbraunm/class\_dicom

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

rbraunm/class\_dicom
====================

PHP library for DICOM tag handling, image conversion, compression, and networking via DCMTK

v2.0.0(1mo ago)2449Apache-2.0PHPPHP &gt;=8.5

Since Sep 2Pushed 2mo agoCompare

[ Source](https://github.com/rbraunm/class_dicom.php)[ Packagist](https://packagist.org/packages/rbraunm/class_dicom)[ RSS](/packages/rbraunm-class-dicom/feed)WikiDiscussions main Synced 6d ago

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

class\_dicom.php
================

[](#class_dicomphp)

A PHP library for working with DICOM medical images: tag reading and writing, JPEG conversion, compression, multiframe-to-video, and DICOM networking (C-ECHO, C-STORE send and receive). It drives the [DCMTK](https://dicom.offis.de/dcmtk.php.en) command-line toolkit under a typed, namespaced PHP API.

Version 2 is a clean-room rewrite on PHP 8.5 with a first-class object API (`DICOM\*`, `PACS\*`) and value objects for dates, names, and UIDs. The original procedural surface (`dicom_tag`, `dicom_convert`, `dicom_net`, and the global helpers) is preserved as a compatibility shim so v1 code keeps running unchanged -- it now emits deprecation notices pointing at the v2 equivalents. See [Migrating from v1](#migrating-from-v1).

Originally created by Dean Vaughan ([deanvaughan.org](http://www.deanvaughan.org/projects/class_dicom_php/)).

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

[](#requirements)

- PHP 8.5 or later (CLI or web)
- [DCMTK](https://dicom.offis.de/dcmtk.php.en) command-line utilities on `PATH`
- `ffmpeg` (only for multiframe-to-video)

On Debian/Ubuntu:

```
apt install php-cli dcmtk ffmpeg
```

DCMTK tools are resolved from `PATH` by default. If your installation lives elsewhere, construct a `DCMTK\Toolkit` with the directory and hand it to whichever object you use (every entry point accepts an optional `Toolkit`):

```
use DCMTK\Toolkit;
use DICOM\File;

$toolkit = new Toolkit('/opt/dcmtk/bin');
$file = File::open('/path/to/image.dcm', $toolkit);
```

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

[](#installation)

```
composer require rbraunm/class_dicom
```

Then load Composer's autoloader (`require __DIR__ . '/vendor/autoload.php';`). There is no single file to copy -- the library is autoloaded.

Quick start
-----------

[](#quick-start)

### Reading tags

[](#reading-tags)

```
use DICOM\File;
use DICOM\Tag;

$file = File::open('/path/to/image.dcm');

// Typed accessors, keyed by the Tag enum -- validated values, not raw strings.
$patient  = $file->getPersonName(Tag::PatientName)?->toDICOM();
$modality = $file->getText(Tag::Modality);
$study    = $file->getDate(Tag::StudyDate)?->iso();
$sopUid   = $file->getUID(Tag::SOPInstanceUID)?->value;

// The full tag map, keyed "gggg,eeee":
$all = $file->dataset()->all();

// A tag with no typed accessor, by raw address:
$rows = $file->dataset()->get(0x0028, 0x0010);
```

### Writing tags

[](#writing-tags)

Typed setters take validated value objects and persist in place:

```
use DICOM\Value\PersonName;

$file->setPersonName(Tag::PatientName, PersonName::fromDICOM('DOE^JOHN'));
$file->setText(Tag::InstitutionName, 'General Hospital');

// Raw write for a tag without a typed setter:
(new DICOM\Dataset('/path/to/image.dcm'))->put(0x0010, 0x0010, 'DOE^JOHN');
```

### DICOM to JPEG

[](#dicom-to-jpeg)

```
use DICOM\Convert;

$convert = new Convert(File::open('/path/to/image.dcm'));
$convert->toJPEG('/tmp/image.jpg', quality: 90);     // windowing defaults to the first VOI window
$convert->toThumbnail('/tmp/image_tn.jpg', widthPixels: 200);
```

### JPEG to DICOM

[](#jpeg-to-dicom)

`Convert::fromJpeg()` builds a Secondary Capture object and generates the study, series, and SOP UIDs; fill identifying tags with typed setters afterward. No XML template is required.

```
use DICOM\Value\Date;

$file = Convert::fromJpeg(['/path/to/photo.jpg'], '/tmp/out.dcm');
$file->setPersonName(Tag::PatientName, PersonName::fromDICOM('DOE^JOHN'));
$file->setText(Tag::PatientID, 'PATIENT001');
$file->setDate(Tag::PatientBirthDate, Date::fromYearMonthDay(1970, 1, 1));
```

### Compression

[](#compression)

```
use DICOM\Compress;
use DICOM\Compression;

$source = File::open('/path/to/image.dcm');
$compressed = (new Compress($source))->compress('/tmp/compressed.dcm', Compression::losslessSV1());
$plain      = (new Compress($source))->decompress('/tmp/uncompressed.dcm');

echo $compressed->transferSyntaxUID();   // e.g. 1.2.840.10008.1.2.4.70
```

### Multiframe to video

[](#multiframe-to-video)

```
use DICOM\FrameTiming;
use DICOM\VideoFormat;

$convert = new Convert(File::open('/path/to/multiframe.dcm'));
$convert->toVideo('/tmp/clip.mp4', FrameTiming::framesPerSecond(24.0), VideoFormat::mp4());
```

### Networking

[](#networking)

```
use DICOM\File;
use PACS\Association;
use PACS\EchoSCU;
use PACS\Peer;
use PACS\SCP;
use PACS\SCU;
use PACS\TransferSyntaxProposal;

$peer = new Peer('192.168.1.100', 104, 'REMOTE_AE');   // host, port, called AE
$association = new Association('MY_AE');                 // calling AE

// C-ECHO (verification) -- throws PACS\Exception\NetworkException on failure.
(new EchoSCU($peer, $association))->verify();

// C-STORE send. Pass a TransferSyntaxProposal to control negotiation.
$scu = new SCU($peer, $association, TransferSyntaxProposal::jpegLossless());
$scu->send(File::open('/path/to/image.dcm'));
$scu->sendDirectory('/path/to/dir');

// C-STORE receive. start() returns a handle; loop for a foreground server.
$scp = new SCP(
    port: 11112,
    outputDirectory: '/var/dicom/incoming',
    postReceiveCommand: '/path/to/handler.php #p #f #c #a',   // dir, file, called AE, calling AE
    forkPerAssociation: true,
    presentationConfigFile: '/path/to/store_server_config.cfg',
);
$process = $scp->start();
while ($process->isRunning()) {
    sleep(1);
}
```

Migrating from v1
-----------------

[](#migrating-from-v1)

Existing v1 code runs unchanged against the compatibility shim, which emits deprecation notices:

```
$d = new dicom_tag('/path/to/image.dcm');   // deprecated; use DICOM\File
$d->load_tags();
$name = $d->get_tag('0010', '0010');
```

The `examples/` directory contains a worked migration for every operation: each script shows the v1 form as a "Before" block and the runnable v2-native "After" that bypasses the shim. A full element-by-element mapping lives in [`docs/migration-v1-to-v2.md`](docs/migration-v1-to-v2.md).

A few migration notes:

- v1's raw `'gggg,eeee'` addresses were only necessary because v1 had no typed access. Prefer the typed accessors; the raw `Dataset` get/put remains for tags without one.
- v1's `jpg_to_dcm()` XML template is gone -- `Convert::fromJpeg()` generates the UIDs and typed setters supply the tags.
- `dicom_net::$transfer_syntax` was inert in v1 (it set nothing); the shim keeps it inert and warns. Use `PACS\TransferSyntaxProposal` with `PACS\SCU` for real negotiation.

Testing
-------

[](#testing)

The suite runs under PHPUnit, with independent oracles (pydicom and pynetdicom) validating that files the library produces are correct when read by a separate implementation -- not just round-tripped through the same tools that wrote them.

```
# System packages
apt install php-cli dcmtk ffmpeg

# Python oracle packages
pip install pydicom pynetdicom Pillow numpy

composer install
composer test
```

API reference
-------------

[](#api-reference)

### v2 API

[](#v2-api)

Namespace / classPurpose`DICOM\File`Open a file; typed get/set accessors keyed by the `Tag` enum`DICOM\Dataset`Raw tag access by group/element (`get`, `put`, `all`)`DICOM\Tag`Enum of known tags`DICOM\Convert`JPEG render, thumbnail, JPEG/PDF import, multiframe video`DICOM\Compress`Compress / decompress pixel data`DICOM\Value\*``PersonName`, `Date`, `Time`, `DateTime`, `UID` value objects`PACS\EchoSCU`C-ECHO verification`PACS\SCU`C-STORE send (`send`, `sendDirectory`)`PACS\SCP`C-STORE receive server`PACS\Peer` / `PACS\Association` / `PACS\TransferSyntaxProposal`Connection, AE, and negotiation settings`DCMTK\Toolkit`Locates the DCMTK binaries (PATH or an explicit directory)### Compatibility shim (deprecated)

[](#compatibility-shim-deprecated)

Class / functionv2 replacement`dicom_tag``DICOM\File` / `DICOM\Dataset``dicom_convert``DICOM\Convert` / `DICOM\Compress``dicom_net``PACS\EchoSCU` / `PACS\SCU` / `PACS\SCP``is_dcm($file)``DICOM\File::isDICOM($path)``Execute($command)``DCMTK\Tool` (internal)Examples
--------

[](#examples)

Each script in `examples/` is a v1-to-v2 migration recipe.

FileOperation`get_tags.php`, `get_tags_webbased.php`Read tags`write_tags.php`Write tags`dcm_to_jpg.php`Render to JPEG + thumbnail`jpg_to_dcm.php`Build a DICOM from a JPEG`compress.php`, `uncompress.php`Compress / decompress`send_dcm.php`C-STORE send one file`send_directory.php`Send and archive a directory`store_server.php`, `store_server_handler.php`, `store_server_config.cfg`C-STORE receive serverAcknowledgments
---------------

[](#acknowledgments)

This library wraps [DCMTK](https://dicom.offis.de/dcmtk.php.en), the DICOM Toolkit developed and maintained by [OFFIS e.V.](https://www.offis.de/en/), a non-profit research institute in Oldenburg, Germany. DCMTK is distributed under a 3-clause BSD license that permits this use freely; it is credited and linked here as a matter of attribution and courtesy, not obligation. DCMTK is a runtime dependency you install separately -- this library invokes its command-line tools and does not bundle or redistribute them.

License
-------

[](#license)

Apache-2.0. See [LICENSE](LICENSE) and [NOTICE](NOTICE).

---

Supported in part by the work of [OneSourceIT](https://onesourceit.us/open-source.html).

###  Health Score

45

—

FairBetter than 91% of packages

Maintenance87

Actively maintained with recent releases

Popularity15

Limited adoption so far

Community10

Small or concentrated contributor base

Maturity59

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 73.1% 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 ~100 days

Total

4

Last Release

45d ago

Major Versions

v1.1.0 → v2.0.02026-06-29

v2.0.0 → v3.0.0-rc12026-06-29

PHP version history (2 changes)v1.1.0PHP &gt;=8.0

v2.0.0PHP &gt;=8.5

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/5680061?v=4)[Randy Braunm](/maintainers/rbraunm)[@rbraunm](https://github.com/rbraunm)

---

Top Contributors

[![vedicveko](https://avatars.githubusercontent.com/u/544487?v=4)](https://github.com/vedicveko "vedicveko (19 commits)")[![rbraunm](https://avatars.githubusercontent.com/u/5680061?v=4)](https://github.com/rbraunm "rbraunm (4 commits)")[![claude-asf28fjas[bot]](https://avatars.githubusercontent.com/u/5680061?v=4)](https://github.com/claude-asf28fjas[bot] "claude-asf28fjas[bot] (2 commits)")[![turbo124](https://avatars.githubusercontent.com/u/5827962?v=4)](https://github.com/turbo124 "turbo124 (1 commits)")

---

Tags

dicompacsdcmtkmedical-imagingdicom-networking

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/rbraunm-class-dicom/health.svg)

```
[![Health](https://phpackages.com/badges/rbraunm-class-dicom/health.svg)](https://phpackages.com/packages/rbraunm-class-dicom)
```

###  Alternatives

[matomo/matomo

Matomo is the leading Free/Libre open analytics platform

21.7k39.6k](/packages/matomo-matomo)[ecotone/ecotone

Enterprise architecture layer for Laravel and Symfony — CQRS, Event Sourcing, Durable Workflows (Sagas, Orchestrators), Projections, and Outbox messaging via PHP attributes.

568591.1k62](/packages/ecotone-ecotone)[civicrm/civicrm-core

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

762297.9k52](/packages/civicrm-civicrm-core)[illuminate/broadcasting

The Illuminate Broadcasting package.

7127.4M234](/packages/illuminate-broadcasting)[logiscape/mcp-sdk-php

Model Context Protocol SDK for PHP

367137.2k15](/packages/logiscape-mcp-sdk-php)[typo3/cms-redirects

TYPO3 CMS Redirects - Create manual redirects, list existing redirects and automatically createredirects on slug changes.

167.6M84](/packages/typo3-cms-redirects)

PHPackages © 2026

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