Blame view

components/artboximage/ArtboxImage.php 1.38 KB
01799a55   Yarik   first commit
1
2
  <?php
      
d0c66642   Yarik   Namespaces
3
      namespace artweb\artbox\components\artboximage;
01799a55   Yarik   first commit
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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
      
      use yii\base\Component;
      use yii\base\ErrorException;
      use yii\image\drivers\Image;
      
      class ArtboxImage extends Component
      {
          /**
           * @var string $driver GD, Imagick ...
           */
          public $driver;
          
          public $presets = [];
          
          /**
           * File path to image locations
           *
           * @var string $rootPath
           */
          public $rootPath;
          
          /**
           * Web path to image locations
           *
           * @var string $rootUrl
           */
          public $rootUrl;
          
          public $extensions = [
              'jpg'  => 'jpeg',
              'jpeg' => 'jpeg',
              'png'  => 'png',
              'gif'  => 'gif',
              'bmp'  => 'bmp',
          ];
          
          /**
           * Try to load image and prepare it to manipulation.
           *
           * @param null|string $file
           * @param null|string $driver
           *
           * @return \yii\image\drivers\Image
           * @throws \yii\base\ErrorException
           */
          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);
          }
      }