Image::__construct PHP Method

__construct() public method

public __construct ( $file )
    public function __construct($file)
    {
        if (!extension_loaded('gd')) {
            exit('Error: PHP GD is not installed!');
        }
        if (file_exists($file)) {
            $this->file = $file;
            $info = getimagesize($file);
            $this->width = $info[0];
            $this->height = $info[1];
            $this->bits = isset($info['bits']) ? $info['bits'] : '';
            $this->mime = isset($info['mime']) ? $info['mime'] : '';
            if ($this->mime == 'image/gif') {
                $this->image = imagecreatefromgif($file);
            } elseif ($this->mime == 'image/png') {
                $this->image = imagecreatefrompng($file);
            } elseif ($this->mime == 'image/jpeg') {
                $this->image = imagecreatefromjpeg($file);
            }
        } else {
            exit('Error: Could not load image ' . $file . '!');
        }
    }

Usage Example

Esempio n. 1
0
 /**
  * Constructor
  *
  * @param integer $ID            
  * @param bool $withWPPost
  *            load into the Post object all members from \WP_Post
  *            
  * @see https://developer.wordpress.org/reference/classes/wp_post/
  */
 public function __construct($ID = 0, $withWPPost = false)
 {
     parent::__construct($ID);
     if ($withWPPost) {
         $this->wpPost = \WP_Post::get_instance($this->ID);
     }
 }
All Usage Examples Of Image::__construct