From the files provided I was able to convert the DRR to jpeg fine (took 2 seconds to generate). When doing the CR image with the default memory setting (in my case 128MB) I got an error as "Fatal error: Allowed memory size of 134217728 bytes exhausted (tried to allocate 14080 bytes) in Nanodicom/tools/pixeler.php on line 825". When I increased the limit to 200MB the image came correctly (as attached), but it took a long time: 1min20secs.
I am using a Macbook since I don't have access to a Windows machine.
Beware that Nanodicom has been optimized for parsing and traversing of the elements of a DICOM file, however, for image rendering it is not the best option (imaging libraries in PHP are memory eaters in my experience). You are better off trying other tools, i.e.. dcmtk or dcm4che
<?php
ini_set('display_errors', 'On');
error_reporting(E_ALL | E_STRICT);
ini_set('memory_limit','200M');
require 'nanodicom.php';
$dir = realpath(dirname(__FILE__)).DIRECTORY_SEPARATOR.'pedro'.DIRECTORY_SEPARATOR;
$files = array();
if ($handle = opendir($dir)) {
while (false !== ($file = readdir($handle)))
{
if ($file != "." && $file != ".." && is_file($dir.$file))
{
$files[] = $file;
}
}
closedir($handle);
}
foreach ($files as $file)
{
$filename = $dir.$file;
// 20) Gets the images from the dicom object if they exist. This example is for gd
try
{
echo "20) Gets the images from the dicom object if they exist. This example is for gd\n";
echo $filename . PHP_EOL;
$dicom = Nanodicom::factory($filename, 'pixeler');
if ( ! file_exists($filename.'.0.jpg'))
{
$images = $dicom->get_images();
// If using another library, for example, imagemagick, the following should be done:
// $images = $dicom->set_driver('imagick')->get_images();
if ($images !== FALSE)
{
foreach ($images as $index => $image)
{
// Defaults to jpg
$dicom->write_image($image, $dir.$file.'.'.$index);
// To write another format, pass the format in second parameter.
// This will write a png image instead
// $dicom->write_image($image, $dir.$file.'.'.$index, 'png');
}
}
else
{
echo "There are no DICOM images or transfer syntax not supported yet.\n";
}
$images = NULL;
}
else
{
echo "Image already exists\n";
}
unset($dicom);
}
catch (Nanodicom_Exception $e)
{
echo 'File failed. '.$e->getMessage()."\n";
}
}
Nano.