ArtboxImage.php 755 Bytes
<?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);
    }
}