DICOM PHP Class
class_dicom.php is a PHP class that lets you work with DICOM files within PHP programs. class_dicom.php enables you to retrieve tags, write tags, convert to JPEG, make thumbnails, convert JPEG to DICOM, compress DICOM, uncompress DICOM, receive DICOM files over the network, and send DICOM files over the network. It even comes with several example programs so you can get started writing your own code right away!
class_dicom.php uses the excellent Offis DICOM Toolkit for it's nitty gritty DICOM work. Your system will need a reasonably recent version of the DICOM Toolkit in order to use class_dicom.php.
Downloading
You can download class_dicom.php directly from this site or from GitHub.
- [Zip File] <- Easy Way
- [tar.gz File]
- [View on Github]
Specifics
class_dicom.php is made up three classes that handle tags, conversions, and network.
class dicom_tag
- load_tags(): Loads all of the tags from a DICOM file into an associative array. Example: examples/get_tags.php
- get_tag(): Returns the value of the group and element you specify. Example: examples/get_tags.php
- write_tags(): Writes the tags contained in an array you specify to a DICOM file. Example: examples/write_tags.php
class dicom_convert
- dcm_to_jpg(): DICOM to JPG. Converts a DICOM file into a JPEG file. Example: examples/dcm_to_jpg.php
- dcm_to_tn(): DICOM to JPG thumbnail. Converts a DICOM file into a JPEG thumb nail. Example: examples/dcm_to_jpg.php
- jpg_to_dcm(): JPG to DICOM. Takes the demographic info in an array you specify and a JPEG file, produces a DICOM file. Example: examples/jpg_to_dcm.php
- compress(): Performs a lossless JPEG compression on a DICOM file. Example: examples/compress.php
- uncompress(): Uncompresses a compressed DICOM file. Example: examples/uncompress.php
class dicom_net
- store_server(): Starts a DICOM receive network service. Example: examples/store_server.php
- echoscu(): Sends a DICOM ping (echoscu).
- send_dcm(): Sends a DICOM file to the host you specify. Example: examples/send_dcm.php
Examples of Examples
These examples and many more are included in the download packages above.
#
# Prints out the DICOM tags in a file specified on the command line
#
require_once('../class_dicom.php');
$file = (isset($argv[1]) ? $argv[1] : '');
if(!$file) {
print "USAGE: ./get_tags.php \n";
exit;
}
if(!file_exists($file)) {
print "$file: does not exist\n";
exit;
}
$d = new dicom_tag;
$d->file = $file;
$d->load_tags();
print_r($d->tags); // PRINT ALL OF THE TAGS
$name = $d->get_tag('0010', '0010'); // GET A SPECIFIC TAG
print "Name: $name\n";
#
# Creates a jpeg and jpeg thumbnail of a DICOM file
#
require_once('../class_dicom.php');
$file = (isset($argv[1]) ? $argv[1] : '');
if(!$file) {
print "USAGE: ./dcm_to_jpg.php \n";
exit;
}
if(!file_exists($file)) {
print "$file: does not exist\n";
exit;
}
$d = new dicom_convert;
$d->file = $file;
$d->dcm_to_tn(); // CONVERT TO JPEG AND A JPEG THUMBNAIL
system("ls -lsh $file*"); // List the files we just created
