/** * Loads an image from the file with the given fileName. * Returns true if the image was successfully loaded; otherwise returns false. * The loader attempts to read the image using the specified format, e.g., PNG or JPG. * * @param string $fileName * @return boolean */ public function load($fileName) { $file = new MFileInfo($fileName); $resource = false; $this->type = $file->getSuffix(); if ($this->type == "png") { $resource = imageCreateFromPng($fileName); if ($resource) { imageAlphaBlending($resource, true); imageSaveAlpha($resource, true); } } else { if ($this->type == "gif") { $resource = imagecreatefromgif($fileName); } else { if ($this->type == "jpg" || $this->type == "jpeg") { $resource = imagecreatefromjpeg($fileName); } else { return false; } } } if ($resource === false) { return false; } $this->resource = $resource; $this->fileName = $fileName; $this->width = imagesx($this->resource); $this->height = imagesy($this->resource); return true; }
private function sortByType(MFileInfo $a, MFileInfo $b) { return strcmp($a->getSuffix(), $b->getSuffix()); }