Пример #1
0
 /**
  * Method to load a file into the JImage object as the resource.
  *
  * @param   string  $path  The filesystem path to load as an image.
  *
  * @return  void
  *
  * @since   11.3
  * @throws  InvalidArgumentException
  * @throws  RuntimeException
  */
 public function loadFile($path)
 {
     // Make sure the file exists.
     if (!file_exists($path)) {
         throw new InvalidArgumentException('The image file does not exist.');
     }
     $properties = WFImage::getImageFileProperties($path);
     if (self::checkMem($properties) === false) {
         throw new RuntimeException('Insufficient memory available to process this image.');
     }
     // Attempt to load the image based on the MIME-Type
     switch ($properties->mime) {
         case 'image/gif':
             // Make sure the image type is supported.
             if (empty(self::$formats[IMAGETYPE_GIF])) {
                 throw new RuntimeException('Attempting to load an image of unsupported type GIF.');
             }
             // Attempt to create the image handle.
             $handle = imagecreatefromgif($path);
             if (!is_resource($handle)) {
                 throw new RuntimeException('Unable to process GIF image.');
             }
             $this->handle = $handle;
             break;
         case 'image/jpeg':
             // Make sure the image type is supported.
             if (empty(self::$formats[IMAGETYPE_JPEG])) {
                 throw new RuntimeException('Attempting to load an image of unsupported type JPG.');
             }
             // Attempt to create the image handle.
             $handle = imagecreatefromjpeg($path);
             if (!is_resource($handle)) {
                 throw new RuntimeException('Unable to process JPG image.');
             }
             $this->handle = $handle;
             break;
         case 'image/png':
             // Make sure the image type is supported.
             if (empty(self::$formats[IMAGETYPE_PNG])) {
                 throw new RuntimeException('Attempting to load an image of unsupported type PNG.');
             }
             // Attempt to create the image handle.
             $handle = imagecreatefrompng($path);
             if (!is_resource($handle)) {
                 throw new RuntimeException('Unable to process PNG image.');
             }
             $this->handle = $handle;
             break;
         default:
             throw new InvalidArgumentException('Attempting to load an image of unsupported type: ' . $properties->mime);
             break;
     }
     // Set the filesystem path to the source image.
     $this->path = $path;
     // set type
     $this->setType(exif_imagetype($path));
 }