Ejemplo n.º 1
0
 /**
  * Create an empty image with the given width and height.
  *
  * @param   integer   image width
  * @param   integer   image height
  * @return  resource
  */
 protected function _create($width, $height)
 {
     $filein = isset($this->filetmp) ? $this->filetmp : $this->file;
     $fileout = tempnam(Upload::$default_directory, '');
     $command = Image_ImageMagick::get_command('convert') . ' ' . escapeshellarg($filein);
     $command .= ' -quality 100 -size ' . escapeshellarg($width) . 'x' . escapeshellarg($height) . ' -flatten';
     $command .= ' ' . escapeshellarg('PNG:' . $fileout);
     exec($command, $response, $status);
     if (!$status) {
         // Delete old tmp file if exist
         if (isset($this->filetmp) && file_exists($this->filetmp)) {
             unlink($this->filetmp);
         }
         // Get the image information
         $info = $this->get_info($fileout);
         // Update image data
         $this->filetmp = $fileout;
         $this->width = $info->width;
         $this->height = $info->height;
         return TRUE;
     }
     return FALSE;
 }
Ejemplo n.º 2
0
 protected function _do_render($type, $quality)
 {
     $tmpfile = tempnam(sys_get_temp_dir(), '');
     // If tmp image file not exist, use original
     $filein = !is_null($this->filetmp) ? $this->filetmp : $this->file;
     $command = Image_ImageMagick::get_command('convert') . ' ' . escapeshellarg($filein);
     $command .= isset($quality) ? ' -quality ' . escapeshellarg($quality) : '';
     $command .= ' ' . escapeshellarg(strtoupper($type) . ':' . $tmpfile);
     exec($command, $response, $status);
     if (!$status) {
         // Capture the output
         ob_start();
         readfile($tmpfile);
         // Delete tmp file
         unlink($tmpfile);
         return ob_get_clean();
     }
     return FALSE;
 }