Exemplo n.º 1
0
 public function thumbnail($width, $height = 0)
 {
     $thumb_folder = $this->thumb_path();
     if (!is_dir($thumb_folder)) {
         @mkdir($thumb_folder, 0777, true);
     }
     $thumb_file = $width . 'x' . $height . '.' . $this->extension;
     if (!is_file($thumb_folder . $thumb_file)) {
         $img = image_create_from_file($this->path);
         $newimg = image_resize_crop($img, $width, $height);
         image_to_file($newimg, $thumb_folder . $thumb_file);
     }
     return is_file($thumb_folder . $thumb_file) ? new self($thumb_folder . $thumb_file) : false;
 }
Exemplo n.º 2
0
 public function get_profile_picture_thumb($width, $height = 0, $template = "iu-resources/uploads/%picture%")
 {
     $path = parse_template($template, $this->stored);
     if ($height > 0 && is_file(str_replace($this->picture, 'thumbs/' . $width . 'x' . $height . '_' . $this->picture, $path))) {
         return base_url() . str_replace($this->picture, 'thumbs/' . $width . 'x' . $height . '_' . $this->picture, $path) . '?rand=' . rand(1, 99999);
     } else {
         $im = image_create_from_file($path);
         $thumb = image_resize_crop($im, $width, $height);
         if ($height == 0) {
             $height = imagesy($thumb);
         }
         $th_path = str_replace($this->picture, 'thumbs/' . $width . 'x' . $height . '_' . $this->picture, $path);
         $ok = image_to_file($thumb, $th_path);
         if ($ok) {
             return base_url() . $th_path . '?rand=' . rand(1, 99999);
         } else {
             return base_url() . $path . '?rand=' . rand(1, 99999);
         }
     }
 }