PHP code example of rbraunm / class_dicom

1. Go to this page and download the library: Download rbraunm/class_dicom library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

rbraunm / class_dicom example snippets


use DCMTK\Toolkit;
use DICOM\File;

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

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);

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');

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);

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));

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

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());

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);
}

$d = new dicom_tag('/path/to/image.dcm');   // deprecated; use DICOM\File
$d->load_tags();
$name = $d->get_tag('0010', '0010');
bash
apt install php-cli dcmtk ffmpeg