Using class_dicom.php on Linux

I develop primarily on Linux and wrote class_dicom.php with Linux in mind. This tutorial will be geared towards CentOS or Fedora as that is what I use on a day to day basis. I’ll try to include notes for Ubuntu/Debian when possible.

I’m going to assume you have at minimum, Linux installed on a PC and you can access the command line as root.

1. Let’s get your environment ready

We’re going to install all of the needed development tools, a web server, and MySQL. A web server and MySQL is not needed by class_dicom.php, but since most folks are going to want to use PHP from a web server, we might as well get it installed.

CentOS:

yum -y groupinstall "Web Server" 'Development Tools' "MySQL Database"

yum -y install wget php php-gd ImageMagick libjpeg zlib libpng libtiff libxml2 libpng-devel zlib-devel libjpeg-devel libtiff-devel libxml-devel libxml2-devel libwrap-devel libpng10-devel  php-mysql

Ubuntu:

sudo apt-get install lamp-server^

sudo apt-get install build-essential wget ImageMagick libjpeg zlib libpng libtiff libxml2 libpng-devel zlib-devel libjpeg-devel libtiff-devel libxml-devel libxml2-devel libwrap-devel libpng10-devel

All of the above will probably take a while to finish out. Note that the ^ in the Ubuntu command is not a typo and needs to be present.

2. Build and install DCMTK

DCMTK is what class_dicom.php uses to actually work with DICOM files. Among many other things, it is a collect of command line tools for working with DICOM files.

The process of building and installing is essentially the same between versions of Linux.

wget ftp://dicom.offis.de/pub/dicom/offis/software/dcmtk/dcmtk360/dcmtk-3.6.0.tar.gz 
tar zxvf dcmtk-3.6.0.tar.gz
cd dcmtk-3.6.0
./configure;make;make install

Depending on your computer, the DCMTK can take a long time to build.

3. Install class_dicom.php

Download a copy:

wget --no-check-certificate http://github.com/vedicveko/class_dicom.php/zipball/master
unzip master
mv vedicveko-class_dicom.php* class_dicom_php

and…. you’re done.

Lets make sure it works!

cd class_dicom_php/examples
./get_tags.php dean.dcm

You should see a header dump of dean.dcm printed to the screen.

17 comments

  1. Hi Dean, thanks for a such a nice tutorial.

    I found Ruby on Rail is required in Ubuntu in order to install the above library. While I found some issues to have Ruby on Rail, Is it possible to get this done with only PHP. Any other PHP extension requirement is fine.

    Thanks again !!!

    1. Hi,

      The class is pure PHP and shouldn’t require any PHP extensions and definitely not Ruby on Rails. If Ubuntu is installing Ruby on Rails for you it probably has to do with some other package having it marked as a requirement. For the scope of the DICOM class you can remove the Ruby packages and the class will work.

  2. Hi. I’m testing this, but when I make it I get empty values:

    ./get_tags.php test.dcm
    Array
    (
    )
    Name:

    How can I solve it?

    1. Hello,

      Is test.dcm in the same directory that you and get_tags.php are in? Do you have the DCMTK installed and if you do, does the TOOLKIT_DIR define in class_dicom.php point to the location of the DCMTK binaries? I would bet that the DCMTK isn’t installed and/or the define isn’t pointing to the right place.

  3. Hey Dean!

    Having quite a bit of trouble getting your library to function. More specifically, difficulties with install. Couldn’t get ImageMagick to install via your instructions. Downloaded via Ubuntu package manager. Now when I execute get_tags.php reponse is:
    Array
    (
    )
    Name:

    Read a previous response re: TOOLKIT_DIR defined in class_dicom.php. Corrected that and dcmtk is installed as well. Same issue. Any further ideas?

    Thanks!

    1. Could you try running “php get_tags.php dean.dcm” from the command line while inside of the examples directory? Also, could you try running “dcmdump dean.dcm” from the same directory? I think either the class isn’t able to find the DICOM toolkit or the DICOM toolkit isn’t working.

  4. Dean,

    I am having trouble with my install. I wanted to try and clear up what I may have done wrong. I think it is a simple mistake on my part but need your input to verify. On step 3 where is the class_dicom.php being installed. The instructions are ambiguous about which directory to be used to me.

    I installed the class_dicom.php in the /var/www/PACS_Tutorial folder.
    Should the class_dicom.php be installed in the dcmtk-3.6.0 folder?

    I am using Debian Lenny.

    Thanks!

  5. Hi
    i jus can’t install this tool.my machne has the following parameters “3.13.0-24-generic #46-Ubuntu SMP Thu Apr 10 19:11:08 UTC 2014 x86_64 x86_64 x86_64 GNU/Linux”.every time i try to issue this command sudo ./configure i get “bash: ./configure: Permission denied” when i ls -la i get drwx—— 1 deemix deemix 4096 Bit 12 08:29 .
    drwx—— 1 deemix deemix 8192 Bit 12 08:36 ..
    -rw——- 1 deemix deemix 9891 Ama 6 2011 ANNOUNCE.360
    -rw——- 1 deemix deemix 462486 Ama 6 2011 CHANGES.360
    drwx—— 1 deemix deemix 4096 Ama 6 2011 CMake
    -rw——- 1 deemix deemix 13794 Ama 6 2011 CMakeLists.txt
    drwx—— 1 deemix deemix 4096 Ama 6 2011 config
    -rw——- 1 deemix deemix 796 Ful 4 2009 configure
    -rw——- 1 deemix deemix 17207 Ama 3 2011 COPYRIGHT
    drwx—— 1 deemix deemix 4096 Ama 6 2011 dcmdata
    drwx—— 1 deemix deemix 4096 Ama 6 2011 dcmimage
    drwx—— 1 deemix deemix 4096 Ama 6 2011 dcmimgle
    drwx—— 1 deemix deemix 4096 Ama 6 2011 dcmjpeg
    drwx—— 1 deemix deemix 4096 Ama 6 2011 dcmjpls
    drwx—— 1 deemix deemix 4096 Ama 6 2011 dcmnet
    drwx—— 1 deemix deemix 4096 Ama 6 2011 dcmpstat
    drwx—— 1 deemix deemix 4096 Ama 6 2011 dcmqrdb
    drwx—— 1 deemix deemix 4096 Ama 6 2011 dcmsign
    drwx—— 1 deemix deemix 4096 Ama 6 2011 dcmsr
    drwx—— 1 deemix deemix 4096 Ama 6 2011 dcmtls
    drwx—— 1 deemix deemix 4096 Ama 6 2011 dcmwlm
    drwx—— 1 deemix deemix 4096 Ama 6 2011 docs
    drwx—— 1 deemix deemix 4096 Ama 6 2011 doxygen
    -rw——- 1 deemix deemix 100 Sad 10 2004 FAQ
    -rw——- 1 deemix deemix 3645 Mud 16 2010 HISTORY
    -rw——- 1 deemix deemix 31157 Bit 12 08:29 INSTALL
    -rw——- 1 deemix deemix 19353 Sad 25 2010 Makefile
    drwx—— 1 deemix deemix 4096 Ama 6 2011 oflog
    drwx—— 1 deemix deemix 4096 Ama 6 2011 ofstd
    -rw——- 1 deemix deemix 2221 Gur 25 2010 README
    -rw——- 1 deemix deemix 6 Ama 6 2011 VERSION

    chmod 755 configure,also does not work.What am i doing wrong ?

  6. worked well thanks for this brief tutorial!
    In addition, I was unable to load the lib* items mentioned; but already have a development environment set up on Ubuntu 14.04 which I am sure was part of the prerequisite for this to install properly.

  7. Hi Mate

    Cheers for your Code. I have a request Actually i want to write a website that allows user to upload DICOM files that need to convert to JPEG files and those files should display to me in my backend. I am looking for any php script for the Dicom to JPEG conversion which should be done in the server itself regardless to the computer of the user

  8. hello,
    I get some messages like “unable to find packed xxx”
    sudo apt-get install build-essential wget ImageMagick libjpeg zlib libpng libtiff libxml2 libpng-devel zlib-devel libjpeg-devel libtiff-devel libxml-devel libxml2-devel libwrap-devel libpng10-devel
    Lecture des listes de paquets… Fait
    Construction de l’arbre des dépendances
    Lecture des informations d’état… Fait
    E: Impossible de trouver le paquet libjpeg
    E: Impossible de trouver le paquet zlib
    E: Impossible de trouver le paquet libpng
    E: Impossible de trouver le paquet libtiff
    E: Impossible de trouver le paquet libpng-devel
    E: Impossible de trouver le paquet zlib-devel
    E: Impossible de trouver le paquet libjpeg-devel
    E: Impossible de trouver le paquet libtiff-devel
    E: Impossible de trouver le paquet libxml-devel
    E: Impossible de trouver le paquet libxml2-devel
    E: Impossible de trouver le paquet libwrap-devel
    E: Impossible de trouver le paquet libpng10-devel

    please could you update the aptget for ubuntu ?
    regards

    1. Looks like the most recent versions of Ubuntu changed some package names. If you google the old name along with your Ubuntu version you’ll be able to get the new names easily enough.

  9. hello
    i’ve instaled this and seems to work fine 😉

    sudo apt-get update
    sudo apt-get install libjpeg-dev libpng12-dev

    sudo apt-get upgrade

    sudo apt-get install libstdc++6

    apt-get install lib32stdc++6

Leave a Reply to Dickson Cancel reply

Your email address will not be published. Required fields are marked *