How Can i save the converted jpg image to a specific directory?

  php

the following code is saving the converted jpg file to the home directory like where the code is placed i want to store it in a folder namely images.
the file dcm-to-jpg is the file that i am executing on the web browser and then all the functions are being called. basically this is a dicom to jpg converter the solution i want is to save the converted file to a new folder that i have already created and also do let me know how to change the name of the file is that possible too??
Thanks in advance!! 🙂

Filename = dcm-to-jpg.php
<?PHP
#
# Creates a jpeg and jpeg thumbnail of a DICOM file 
#

require_once('../class_dicom.php');

$file = (isset($argv[1]) ? $argv[1] : 'image1.dcm');

if(!$file) {
  print "USAGE: ./dcm_to_jpg.php <FILE>n";
  exit;
}

if(!file_exists($file)) {
  print "$file: does not existn";
  exit;
}

$job_start = time();

$d = new dicom_convert;
$d->file = $file;
$d->dcm_to_jpg();


copy($d, "images/");

system("ls -lsh $file*");

$job_end = time();
$job_time = $job_end - $job_start;
print "Created JPEG and thumbnail in $job_time seconds.n";


?>



filename = class_dicom.php
### Convert a DICOM image to JPEG. $this->file is the filename of the image.
### $this->jpg_quality is an optional value (0-100) that'll set the quality of the JPEG produced
  function dcm_to_jpg() {

    $filesize = 0;

    $this->jpg_file = $this->file . '.jpg';
   
    $convert_cmd = BIN_DCMJ2PNM . " +oj +Jq " . $this->jpg_quality . " --use-window 1 "" . $this->file . "" "" . $this->jpg_file . """;
    $out = Execute($convert_cmd);

    if(file_exists($this->jpg_file)) {
      $filesize = filesize($this->jpg_file);
    }

    if($filesize < 1) {
      $convert_cmd = BIN_DCMJ2PNM . " +Wm +oj +Jq " . $this->jpg_quality . " "" . $this->file . "" "" . $this->jpg_file . """;
      $out = Execute($convert_cmd);
    }

    return($this->jpg_file);

  }
?>

Source: Ask PHP

LEAVE A COMMENT