Ejemplo n.º 1
0
 /**
  * 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;
 }
Ejemplo n.º 2
0
 /**
  * Returns true if the directory <i>$path</i> is relative; otherwise returns 
  * false. (Under Unix a path is relative if it does not start with a "/").
  * 
  * @param string $path
  * @return boolean
  */
 public function isRelativePath($path)
 {
     MDataType::mustBeString($path);
     $fileInfo = new MFileInfo($path);
     return $fileInfo->isAbsolute() === false;
 }