public function view() { $manager = new Pass_File_Manager($this->pass); $pass = $this->pass; $this->echo_img = function ($name) use($manager, $pass) { if (file_exists($manager->file_path($name))) { echo \Fuel\Core\Html::img(\Fuel\Core\Uri::create('admin/pass/image/' . $pass->id . '/' . $name), array('alt' => str_replace('.png', '', $name))); } }; $image_names = array('icon.png', '*****@*****.**', 'logo.png', '*****@*****.**', 'background.png', '*****@*****.**', 'footer.png', '*****@*****.**', 'strip.png', '*****@*****.**', 'thumbnail.png', '*****@*****.**'); $this->images = array_map(function ($image_name) use($manager) { if (file_exists($manager->file_path($image_name))) { return array('name' => $image_name, 'sizes' => \Fuel\Core\Image::sizes($manager->file_path($image_name))); } else { return null; } }, array_filter($image_names, function ($image_name) use($manager) { if (file_exists($manager->file_path($image_name))) { return true; } else { return false; } })); $this->upload_image_selection = $manager->required_images_readable(); }
public static function resize_photo($path, $photo, $type = null) { $file = $path . $photo; if (File::exists($file)) { $rotate_number = self::exifRotation($file); $image_config = Config::get('app.image'); if (!is_dir($path . $type)) { mkdir($path . $type, 0755); } switch ($type) { case 'icon': @Image::load($path . $photo)->rotate($rotate_number)->resize($image_config[$type], $image_config[$type], false)->save($path . $type . '/' . $photo); break; case 'category': case 'product': @Image::load($path . $photo)->rotate($rotate_number)->resize($image_config[$type], null, true)->save($path . $type . '/' . $photo); break; case 'photo': foreach ($image_config[$type] as $version => $size) { if (!is_dir($path . $type . '/' . $version)) { mkdir($path . $type . '/' . $version, 0700); } @Fuel\Core\Image::load($path . $photo)->rotate($rotate_number)->resize($size, null, true)->save($path . $type . '/' . $version . '/' . $photo); } break; default: break; } File::delete($path . $photo); return true; } return false; }
public function action_file($folder = null, $size = null, $crop = 'no') { try { if (is_null($folder)) { throw new Exception('Folder name is not given!'); } if (is_null($size)) { throw new Exception('Image file name is not given!'); } if (!strpos($size, 'x')) { throw new Exception('Image size is not given!'); } if (!\Fuel\Core\Input::get('image')) { throw new Exception('Image is not given!'); } $file = \Fuel\Core\Input::get('image'); /** @var $upload_path */ $upload_path = '/var/www/html/' . $this->_dir; /** @var $file_path */ $file_path = $folder . '/' . $file; /** @var $real_path */ $real_path = $upload_path . '/' . $file_path; /** @var $new_name */ $new_name = $size . '_' . $file; /** @var $resize_path : Path for resize only */ $resize_path = $upload_path . '/' . $folder . '/resize/'; /** @var $resize_file */ $resize_file = $upload_path . '/' . $folder . '/resize/' . $new_name; /** @var $crop_path : Path for crop only */ $crop_path = $upload_path . '/' . $folder . '/crop/'; /** @var $crop_file */ $crop_file = $upload_path . '/' . $folder . '/crop/' . $new_name; /** @var $image */ $image = \Fuel\Core\Image::forge(array('driver' => 'gd', 'bgcolor' => null, 'quality' => 100)); /** @var $where_are_file */ $where_are_file = ''; /** @var $where_are_path */ $where_are_path = ''; if ($crop == 'no') { $where_are_file = $resize_file; $where_are_path = $resize_path; } else { $where_are_file = $crop_file; $where_are_path = $crop_path; } if (!file_exists($where_are_file)) { /** * Check if not dir then make it. */ if (!is_dir($where_are_path)) { if (!mkdir($where_are_path, 0777)) { throw new Exception('Permission denied!'); } } /** @var $size */ $size = explode('x', $size); if ($crop == 'crop') { /** * Chaining to crop_resize() function */ $image->load($real_path)->crop_resize($size[0], $size[1])->save($where_are_file); } else { /** * Chaining to resize() function */ $image->load($real_path)->resize($size[0], $size[1], true, false)->save($where_are_file); } /** * Load file and output image. */ $image->load($where_are_file)->output(); } else { /** * If file exist force output to show image. */ if (\Fuel\Core\Input::get('action') == 'delete') { if (\Auth\Auth::instance()->get('group') == 100) { $model = Model_Filemanager::find_by_value($file); if ($model) { $model->deleted_at = time(); $model->value = null; if ($model->save()) { \Fuel\Core\File::delete($where_are_file); \Fuel\Core\File::delete($real_path); \Fuel\Core\Response::redirect('filemanager/folder/' . $folder); } else { throw new Exception('Cannot delete in database!'); } } else { throw new Exception('Image not found!'); } } else { throw new Exception('You are not an Administrator!'); } } else { $image->load($where_are_file)->output(); } } } catch (Exception $e) { /** @var $error */ $error = '<ul>'; $error .= '<li>' . $e->getLine() . '</li>'; $error .= '<li>' . $e->getFile() . '</li>'; $error .= '<li>' . $e->getMessage() . '</li>'; $error .= '</ul>'; return $error; } exit; }