imtDicom.php 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  1. <?php
  2. header('Content-Type:text/xml');
  3. ?>
  4. <?php
  5. define("DIR_DICOM_FS", getcwd() . "/");
  6. $rest = array();
  7. $pixelspacingX = 0;
  8. $pixelspacingY = 0;
  9. $physicalDeltaX = 0;
  10. $physicalDeltaY = 0;
  11. $filename = $_GET["filename"] ;
  12. $fname = DIR_DICOM_FS."upload/".$filename;
  13. $fname = str_replace("'","_",$fname);
  14. require_once(DIR_DICOM_FS."DICOM.php");
  15. $dicom = new File_DICOM();
  16. $isDicom = $dicom->isDicom($fname);
  17. if (!$isDicom)
  18. {
  19. echo "File is not DICOM. Please try again";
  20. exit();
  21. }
  22. $res = $dicom->parse($fname);
  23. if (isset($dicom->_elements[0x7FE0][0x0010]))
  24. {
  25. // Récupère les tags Dicom qui nous intéressent
  26. if (isset($dicom->_elements[0x0018][0x602c]))
  27. {
  28. $physicalDeltaX = $dicom->_elements[0x0018][0x602c][0]->value;
  29. }
  30. if (isset($dicom->_elements[0x0018][0x602e]))
  31. {
  32. $physicalDeltaY = $dicom->_elements[0x0018][0x602e][0]->value;
  33. }
  34. if (isset($dicom->_elements[0x0028][0x0030]))
  35. {
  36. $pixelspacingX = $dicom->_elements[0x0028][0x0030][0]->value;
  37. }
  38. if (isset($dicom->_elements[0x0028][0x0030]))
  39. {
  40. $pixelspacingY = $dicom->_elements[0x0028][0x0030][1]->value;
  41. }
  42. // Return the resource image alone
  43. $images = $dicom->imagecreatefromDICOM($fname);
  44. if (!empty($images))
  45. {
  46. foreach ($images as $im)
  47. {
  48. // Cryptage de l'image
  49. header("Content-type:image/jpeg");
  50. $dimh = imagesx($im);
  51. $dimv = imagesy($im);
  52. $ncol = ($dimv * 12) / 100;
  53. $red = 0;
  54. $green = 0;
  55. $blue = 0;
  56. $background = imagecolorallocate($im, $red, $green, $blue);
  57. $white = imagecolorallocate($im, 255, 255, 255);
  58. ImageFilledRectangle($im, 0, 0, $dimh, $ncol, $background);
  59. ImageFilledRectangle($im, 0, ($dimv - $ncol), $dimh, $dimv, $background);
  60. $idpatient = $_GET{'idpatient'};
  61. $lastname = $_GET{'lastname'};
  62. $firstname = $_GET{'firstname'};
  63. $sex = $_GET{'sex'};
  64. $birthdate = $_GET{'birthdate'};
  65. $text_h = $dimv - imagefontheight(12) - 20;
  66. $text_v = 20;
  67. imagestring($im, 12, $text_v, $text_h, $lastname.' '.$firstname.' '.$birthdate.' ('.$sex.') '.$idpatient, $white);
  68. // Enregistrement de l'image
  69. imagejpeg($im, $fname.".jpg", 100);
  70. imagejpeg($im, $fname.".jpg");
  71. chmod($fname.".jpg", 0755);
  72. imagedestroy($im);
  73. }
  74. }
  75. }
  76. // on retourne les Tags
  77. print($filename);
  78. print('_TAG_');
  79. print ($physicalDeltaX);
  80. print('_TAG_');
  81. print ($physicalDeltaY);
  82. print('_TAG_');
  83. print ($pixelspacingX);
  84. print('_TAG_');
  85. print ($pixelspacingY);
  86. print('_TAG_');
  87. ?>