Ticket #597: ImageMagick.diff

File ImageMagick.diff, 1.3 kB (added by tterragcnoom, 4 months ago)

system/libraries/drivers/Image/ImageMagick.php

  • (clipboard)

    old new  
    5353         * Creates a temporary image and executes the given actions. By creating a 
    5454         * temporary copy of the image before manipulating it, this process is atomic. 
    5555         */ 
    56         public function process($image, $actions, $dir, $file
     56        public function process($image, $actions, $dir, $file, $output = FALSE
    5757        { 
    5858                // We only need the filename 
    5959                $image = $image['file']; 
     
    7272 
    7373                // All calls to these will need to be escaped, so do it now 
    7474                $this->cmd_image = escapeshellarg($this->tmp_image); 
    75                 $this->new_image = escapeshellarg($dir.$file); 
     75                $this->new_image = ($output)?$this->cmd_image:escapeshellarg($dir.$file); 
    7676 
    7777                if ($status = $this->execute($actions)) 
    7878                { 
     
    8282                        if ($error = exec(escapeshellcmd($this->dir.'convert'.$this->ext).' -quality '.$quality.'% '.$this->cmd_image.' '.$this->new_image)) 
    8383                        { 
    8484                                $this->errors[] = $error; 
     85                        }else{ 
     86                                if ($output != FALSE){ 
     87                                        $contents = file_get_contents($this->tmp_image); 
     88                                        switch (substr($file, strrpos($file, '.') + 1)) 
     89                                        { 
     90                                                case 'jpg': 
     91                                                case 'jpeg': 
     92                                                        header ("Content-Type: image/jpeg"); 
     93                                                break; 
     94                                                case 'gif': 
     95                                                        header ("Content-Type: image/gif"); 
     96                                                break; 
     97                                                case 'png': 
     98                                                        header ("Content-Type: image/png"); 
     99                                                break; 
     100                                        } 
     101                                        echo ($contents); 
     102                                } 
    85103                        } 
    86104                } 
    87105