Blame view

common/components/artboximage/ArtboxImage.php 755 Bytes
1f90c5f4   Karnovsky A   ArtboxImage resizer
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
  <?php
  
  namespace common\components\artboximage;
  
  use Yii;
  use yii\base\Component;
  use yii\base\ErrorException;
  use yii\image\drivers\Image;
  
  //use common\components\artboximage\drivers\Image;
  
  class ArtboxImage extends Component {
  
      public $driver;
  
      public $presets = [];
  
      public $rootPath;
      public $rootUrl;
  
      public $extensions = [
          'jpg' => 'jpeg',
          'jpeg' => 'jpeg',
          'png' => 'png',
          'gif' => 'gif',
          'bmp' => 'bmp',
      ];
  
      public function load($file = null, $driver = null) {
          if(empty($file) || !realpath($file)) {
              throw new ErrorException('File name can not be empty and exists');
          }
          return Image::factory($file, $driver ? $driver : $this->driver);
      }
  }