public function __construct($file)
{
if (!extension_loaded('gd')) {
throw new GdException('gd is not installed, or the extension is not loaded');
}
$this->_file = realpath($this->alias->resolve($file));
if (!$this->_file) {
throw new GdException('`:file` file is not exists', ['file' => $file]);
}
$imageInfo = getimagesize($this->_file);
$this->_width = $imageInfo[0];
/** @noinspection MultiAssignmentUsageInspection */
$this->_height = $imageInfo[1];
/** @noinspection MultiAssignmentUsageInspection */
$type = $imageInfo[2];
if ($type === IMAGETYPE_GIF) {
$this->_image = imagecreatefromgif($this->_file);
} elseif ($type === IMAGETYPE_JPEG) {
$this->_image = imagecreatefromjpeg($this->_file);
} elseif ($type === IMAGETYPE_PNG) {
$this->_image = imagecreatefrompng($this->_file);
} else {
throw new GdException('Installed GD does not support such images');
}
imagesavealpha($this->_image, true);
}