Eventviva\ImageResize::__construct PHP Method

__construct() public method

Loads image source and its properties to the instanciated object
public __construct ( string $filename ) : ImageResize
$filename string
return ImageResize
    public function __construct($filename)
    {
        $image_info = @getimagesize($filename);
        if (!$image_info) {
            throw new \Exception('Could not read file');
        }
        list($this->original_w, $this->original_h, $this->source_type) = $image_info;
        switch ($this->source_type) {
            case IMAGETYPE_GIF:
                $this->source_image = imagecreatefromgif($filename);
                break;
            case IMAGETYPE_JPEG:
                $this->source_image = $this->imageCreateJpegfromExif($filename);
                // set new width and height for image, maybe it has changed
                $this->original_w = ImageSX($this->source_image);
                $this->original_h = ImageSY($this->source_image);
                break;
            case IMAGETYPE_PNG:
                $this->source_image = imagecreatefrompng($filename);
                break;
            default:
                throw new \Exception('Unsupported image type');
                break;
        }
        if (!$this->source_image) {
            throw new \Exception('Could not load image');
        }
        return $this->resize($this->getSourceWidth(), $this->getSourceHeight());
    }