Exemplo n.º 1
0
 if (!($size = @getimagesize($file['tmp_name']))) {
     error($config['error']['invalidimg']);
 }
 if ($size[0] > $config['max_width'] || $size[1] > $config['max_height']) {
     error($config['error']['maxsize']);
 }
 if ($config['convert_auto_orient'] && ($file['extension'] == 'jpg' || $file['extension'] == 'jpeg')) {
     // The following code corrects the image orientation.
     // Currently only works with the 'convert' option selected but it could easily be expanded to work with the rest if you can be bothered.
     if (!($config['redraw_image'] || $config['strip_exif'] && !$config['use_exiftool'] && ($file['extension'] == 'jpg' || $file['extension'] == 'jpeg'))) {
         if (in_array($config['thumb_method'], array('convert', 'convert+gifsicle', 'gm', 'gm+gifsicle'))) {
             $exif = @exif_read_data($file['tmp_name']);
             $gm = in_array($config['thumb_method'], array('gm', 'gm+gifsicle'));
             if (isset($exif['Orientation']) && $exif['Orientation'] != 1) {
                 if ($config['convert_manual_orient']) {
                     $error = shell_exec_error(($gm ? 'gm ' : '') . 'convert ' . escapeshellarg($file['tmp_name']) . ' ' . ImageConvert::jpeg_exif_orientation(false, $exif) . ' ' . ($config['strip_exif'] ? '+profile "*"' : ($config['use_exiftool'] ? '' : '+profile "*"')) . ' ' . escapeshellarg($file['tmp_name']));
                     if ($config['use_exiftool'] && !$config['strip_exif']) {
                         if ($exiftool_error = shell_exec_error('exiftool -overwrite_original -q -q -orientation=1 -n ' . escapeshellarg($file['tmp_name']))) {
                             error(_('exiftool failed!'), null, $exiftool_error);
                         }
                     } else {
                         // TODO: Find another way to remove the Orientation tag from the EXIF profile
                         // without needing `exiftool`.
                     }
                 } else {
                     $error = shell_exec_error(($gm ? 'gm ' : '') . 'convert ' . escapeshellarg($file['tmp_name']) . ' -auto-orient ' . escapeshellarg($upload));
                 }
                 if ($error) {
                     error(_('Could not auto-orient image!'), null, $error);
                 }
                 $size = @getimagesize($file['tmp_name']);
Exemplo n.º 2
0
 public function resize()
 {
     global $config;
     if ($this->temp) {
         // remove old
         $this->destroy();
     }
     $this->temp = tempnam($config['tmp'], 'convert');
     $config['thumb_keep_animation_frames'] = (int) $config['thumb_keep_animation_frames'];
     if ($this->format == 'gif' && ($config['thumb_ext'] == 'gif' || $config['thumb_ext'] == '') && $config['thumb_keep_animation_frames'] > 1) {
         if ($this->gifsicle) {
             if (($error = shell_exec("gifsicle -w --unoptimize -O2 --resize {$this->width}x{$this->height} < " . escapeshellarg($this->src . '') . " \"#0-{$config['thumb_keep_animation_frames']}\" -o " . escapeshellarg($this->temp))) || !file_exists($this->temp)) {
                 $this->destroy();
                 error(_('Failed to resize image!'), null, $error);
             }
         } else {
             if ($config['convert_manual_orient'] && ($this->format == 'jpg' || $this->format == 'jpeg')) {
                 $convert_args = str_replace('-auto-orient', ImageConvert::jpeg_exif_orientation($this->src), $config['convert_args']);
             } elseif ($config['convert_manual_orient']) {
                 $convert_args = str_replace('-auto-orient', '', $config['convert_args']);
             } else {
                 $convert_args =& $config['convert_args'];
             }
             if (($error = shell_exec_error(($this->gm ? 'gm ' : '') . 'convert ' . sprintf($convert_args, $this->width, $this->height, escapeshellarg($this->src), $this->width, $this->height, escapeshellarg($this->temp)))) || !file_exists($this->temp)) {
                 $this->destroy();
                 error(_('Failed to resize image!'), null, $error);
             }
             if ($size = $this->get_size($this->temp)) {
                 $this->width = $size[0];
                 $this->height = $size[1];
             }
         }
     } else {
         if ($config['convert_manual_orient'] && ($this->format == 'jpg' || $this->format == 'jpeg')) {
             $convert_args = str_replace('-auto-orient', ImageConvert::jpeg_exif_orientation($this->src), $config['convert_args']);
         } elseif ($config['convert_manual_orient']) {
             $convert_args = str_replace('-auto-orient', '', $config['convert_args']);
         } else {
             $convert_args =& $config['convert_args'];
         }
         if (($error = shell_exec_error(($this->gm ? 'gm ' : '') . 'convert ' . sprintf($convert_args, $this->width, $this->height, escapeshellarg($this->src . '[0]'), $this->width, $this->height, escapeshellarg('jpg:' . $this->temp)))) || !file_exists($this->temp)) {
             if (strpos($error, "known incorrect sRGB profile") === false && strpos($error, "iCCP: Not recognizing known sRGB profile that has been edited") === false) {
                 $this->destroy();
                 error(_('Failed to resize image!') . " " . _('Details: ') . nl2br(htmlspecialchars($error)), null, array('convert_error' => $error));
             }
             if (!file_exists($this->temp)) {
                 $this->destroy();
                 error(_('Failed to resize image!'), null, $error);
             }
         }
         if ($size = $this->get_size($this->temp)) {
             $this->width = $size[0];
             $this->height = $size[1];
         }
     }
 }
Exemplo n.º 3
0
 public function resize()
 {
     global $config;
     if ($this->temp) {
         // remove old
         $this->destroy();
     }
     $this->temp = tempnam($config['tmp'], 'convert');
     $config['thumb_keep_animation_frames'] = (int) $config['thumb_keep_animation_frames'];
     if ($this->format == 'gif' && ($config['thumb_ext'] == 'gif' || $config['thumb_ext'] == '') && $config['thumb_keep_animation_frames'] > 1) {
         if ($this->gifsicle) {
             if (($error = shell_exec("gifsicle -w --unoptimize -O2 --resize {$this->width}x{$this->height} < " . escapeshellarg($this->src . '') . " \"#0-{$config['thumb_keep_animation_frames']}\" -o " . escapeshellarg($this->temp))) || !file_exists($this->temp)) {
                 $this->destroy();
                 error(_('Failed to resize image!'), null, $error);
             }
         } else {
             if ($config['convert_manual_orient'] && ($this->format == 'jpg' || $this->format == 'jpeg')) {
                 $convert_args = str_replace('-auto-orient', ImageConvert::jpeg_exif_orientation($this->src), $config['convert_args']);
             } elseif ($config['convert_manual_orient']) {
                 $convert_args = str_replace('-auto-orient', '', $config['convert_args']);
             } else {
                 $convert_args =& $config['convert_args'];
             }
             if (($error = shell_exec_error(($this->gm ? 'gm ' : '') . 'convert ' . sprintf($convert_args, $this->width, $this->height, escapeshellarg($this->src), $this->width, $this->height, escapeshellarg($this->temp)))) || !file_exists($this->temp)) {
                 $this->destroy();
                 error('Failed to resize image!', null, $error);
             }
             if ($size = $this->get_size($this->temp)) {
                 $this->width = $size[0];
                 $this->height = $size[1];
             }
         }
     } else {
         if ($config['convert_manual_orient'] && ($this->format == 'jpg' || $this->format == 'jpeg')) {
             $convert_args = str_replace('-auto-orient', ImageConvert::jpeg_exif_orientation($this->src), $config['convert_args']);
         } elseif ($config['convert_manual_orient']) {
             $convert_args = str_replace('-auto-orient', '', $config['convert_args']);
         } else {
             $convert_args =& $config['convert_args'];
         }
         if (($error = shell_exec_error(($this->gm ? 'gm ' : '') . 'convert ' . sprintf($convert_args, $this->width, $this->height, escapeshellarg($this->src . '[0]'), $this->width, $this->height, escapeshellarg($this->temp)))) || !file_exists($this->temp)) {
             $this->destroy();
             error('Failed to resize image!', null, $error);
         }
         if ($size = $this->get_size($this->temp)) {
             $this->width = $size[0];
             $this->height = $size[1];
         }
     }
 }