Beispiel #1
0
 private function resizeForEditor($filename, $width = false, $height = false)
 {
     $filename = preg_replace('/uploads\\//i', '/', $filename);
     if (!file_exists($this->dirImages . $filename) || !is_file($this->dirImages . $filename)) {
         return false;
     }
     $imag_info = @getimagesize($this->dirImages . $filename);
     if (!$imag_info) {
         return;
     }
     $info = pathinfo($filename);
     $extension = $info['extension'];
     if ($height && !$width) {
         $width = round($imag_info[0] / ($imag_info[1] / $height));
     } elseif ($width && !$height) {
         $height = round($imag_info[1] / ($imag_info[0] / $width));
     }
     if (!$width || !$height) {
         return false;
     }
     $old_image = $filename;
     $new_image = 'cache' . substr($filename, 0, strrpos($filename, '.')) . '-' . $width . 'x' . $height . '.' . $extension;
     if (!file_exists($this->dirImages . $new_image) || filemtime($this->dirImages . $old_image) > filemtime($this->dirImages . $new_image)) {
         $path = '';
         $directories = explode('/', dirname(str_replace('../', '', $new_image)));
         foreach ($directories as $directory) {
             $path = $path . '/' . $directory;
             if (!file_exists($this->dirImages . $path)) {
                 @mkdir($this->dirImages . $path, 0777, true);
             }
         }
         $image = new JO_GDThumb($this->dirImages . $old_image);
         $image->resize($width, $height, false);
         $image->save($this->dirImages . $new_image);
     }
     return $this->httpImages . $new_image;
 }