Creating a resource of GD image file
@param string $imageFile image file path
@return resource
@throws Exception
516964
protected function getGdResource($imageFile)
    {
        $imageInfo = getimagesize($imageFile);

        switch($imageInfo['mime'])
        {
            case 'image/jpg':
            case 'image/jpeg':
                return $this->normalizeGdResource(imagecreatefromjpeg($imageFile));

            case 'image/gif':
                return $this->normalizeGdResource(imagecreatefromgif($imageFile));

            case 'image/png':
                return $this->normalizeGdResource(imagecreatefrompng($imageFile));
        }

        throw new Exception('GD resource not supported image extension');
    }
357972
public function createFromSource()
    {
        /**
         * A work-around for some improperly formatted, but
         * usable JPEGs; known to be produced by Samsung
         * smartphones' front-facing cameras.
         *
         * @see    https://bugs.php.net/bug.php?id=72404
         */
        ini_set('gd.jpeg_ignore_warning', 1);

        $mime = $this->sourceImageFile->getMime();
        $mime = is_array($mime) ? $mime[ 0 ] : $mime;

        try {
            switch ($mime) {
                case 'image/jpg':
                case 'image/jpeg':
                    $this->sourceImageResource = imagecreatefromjpeg($this->sourceImageFile->getRealPath());
                    break;

                case 'image/gif':
                    $this->sourceImageResource = imagecreatefromgif($this->sourceImageFile->getRealPath());
                    break;

                case 'image/png':
                case 'image/x-png':
                    $this->sourceImageResource = imagecreatefrompng($this->sourceImageFile->getRealPath());
                    break;
            }

            // Convert pallete images to true color images
            imagepalettetotruecolor($this->sourceImageResource);
        } catch (\Exception $e) {

        }
    }
789927
public static function LoadFile( string $imageFile ) : GdImage
   {

      if ( ! \file_exists( $imageFile ) )
      {
         throw new FileNotFoundError(
            'Drawing.Image', $imageFile, 'Loading a \Beluga\Drawing\Image\GdImage Resource from this file fails.'
         );
      }

      $imageInfo = null;

      try
      {
         if ( false === ( $imageInfo = \getimagesize( $imageFile ) ) )
         {
            throw new \Exception( 'Defined imagefile uses a unknown file format!' );
         }
      }
      catch ( \Throwable $ex )
      {
         throw new FileAccessError(
            'Drawing.Image', $imageFile, FileAccessError::ACCESS_READ, $ex->getMessage()
         );
      }

      $img  = null;
      $mime = null;

      switch ( $imageInfo[ 'mime' ] )
      {

         case 'image/png':
            $img = \imagecreatefrompng( $imageFile );
            $mime = 'image/png';
            break;

         case 'image/gif':
            $img = \imagecreatefromgif( $imageFile );
            $mime = 'image/gif';
            break;

         default:
            $img = \imagecreatefromjpeg( $imageFile );
            $mime = 'image/jpeg';
            break;

      }

      return new GdImage(
         $img,
         new Size( $imageInfo[ 0 ], $imageInfo[ 1 ] ),
         $mime,
         $imageFile
      );

   }
1083976
public static function create($path, $format)
    {
        switch ($format) {
            case IMAGETYPE_JPEG:
                $result = imagecreatefromjpeg($path);
                break;
            case IMAGETYPE_PNG:
                $result = imagecreatefrompng($path);
                break;
            case IMAGETYPE_GIF:
                $result = imagecreatefromgif($path);
                break;
        }

        if (!$result) {
            throw new \Exception("Failing to create image (" . $path . ")");
        }

        return $result;
    }
772071
public function setPropertyFile($propertyFile)
    {
        if (!file_exists($this->getDirectory() . DIRECTORY_SEPARATOR . $propertyFile)) {
            throw new \Exception(Lang::get('property_file_missing'));
        }

        $this->propertyFile = $propertyFile;
    }
843840
public function setImageUrl($imageUrl)
    {
        if (false === ($imageString = file_get_contents($imageUrl))) {
            throw new FileNotFoundException('IMAGE_E_URL_INVALID', 0, [$imageUrl]);
        }

        // Create image source resource
        $this->driver->createFromString($imageString);

        return $this;
    }
479769
static function createImage( $width, $height, &$useTruecolor )
    {
        if ( $useTruecolor === null )
        {
//             print( "has GD2='" . eZImageInterface::hasGD2() . "'<br/>" );
            $useTruecolor = eZImageInterface::hasGD2();
        }
        if ( $useTruecolor and
             !function_exists( 'ImageCreateTrueColor' ) )
        {
            eZDebug::writeWarning( 'Function ImageCreateTrueColor does not exist, cannot create true color images', __METHOD__ );
            $useTruecolor = false;
        }
        if ( $useTruecolor )
            $imageObject = ImageCreateTrueColor( $width, $height );
        else
            $imageObject = ImageCreate( $width, $height );
        return $imageObject;
    }
1007174
public function setImage($imageUrl)
    {
        $this->openGraph()->setImage($imageUrl);
        $this->twitter()->addImage($imageUrl);

        return $this;
    }
429749
public function get($localFile, $remoteFile, $resumePosision = 0)
    {
        $mode = $this->getMode();
        $result = @ftp_get($this->connection, $localFile, $remoteFile, $mode, $resumePosision);

        if ($result === false)
        {
            throw new Exception(sprintf('Unable to get or save file "%s" from %s', $localFile, $remoteFile));
        }

        return $this;
    }
393753
private static function _guessType( $imageFile ){
        // Values from http://php.net/manual/en/image.constants.php starting with IMAGETYPE_GIF.
        // 0 - unknown,
        // 1 - GIF,
        // 2 - JPEG,
        // 3 - PNG
        // 15 - WBMP
        list($width, $height, $type) = getimagesize( $imageFile );

        unset($width, $height);

        if ( 1 == $type) {

            return ImageType::GIF;

        } else if ( 2 == $type) {

            return ImageType::JPEG;

        } else if ( 3 == $type) {

            return ImageType::PNG;

        } else if ( 15 == $type) {

            return ImageType::WBMP;

        }

        return ImageType::UNKNOWN;
    }
1295504
public function createImageResource($keepHandleAlive = false): ImageResource {
		return new ImageResource(IoUtils::imageCreateFromWebp($this->filePath), $keepHandleAlive);
	}
1098958
public function createImageResource($keepHandleAlive = false): ImageResource {
		return new ImageResource(IoUtils::imageCreateFromGif($this->filePath), $keepHandleAlive);
	}
597193
public static function getImageOrientation($imageFile) {
		if (!file_exists($imageFile)) {
			throw new \RuntimeException(sprintf('File %s not found!', $imageFile));
		}
		$exif = exif_read_data($imageFile);
		if ($exif === false) {
			return false;
		}
		$angle = 0;
		if (!empty($exif['Orientation'])) {
			switch ($exif['Orientation']) {
				case 0:
					$angle = 0;
					break;
				case 3:
					$angle = 180;
					break;
				case 6:
					$angle = -90;
					break;
				case 8:
					$angle = 90;
					break;
				default:
					$angle = 0;
					break;
			}
			return $angle;
		}
		return $angle;
	}
830339
protected function initSourceImageResource() 
    { 
    	$ext = $this->getExtension();
    	
    	switch($ext) {
		case 'gif':
			$this->sourceImageResource = ImageCreateFromGif($this->sourceImagePath);
			break;
    	
		case 'jpg':
			$this->sourceImageResource = ImageCreateFromJpeg($this->sourceImagePath);
			break;
    	
		case 'png':
			$this->sourceImageResource = ImageCreateFromPng($this->sourceImagePath);
			break;
    	
		default:
			throw new \RuntimeException("An error occurred trying to create the image, extension '" . $ext. "' is not supported");
			break;
    	}
    	
    	return $this;
    }
1259853
private function createImagineInstance()
    {
        try {
            if (ImagerService::$imageDriver === 'gd') {
                return new \Imagine\Gd\Imagine();
            }

            if (ImagerService::$imageDriver === 'imagick') {
                return new \Imagine\Imagick\Imagine();
            }
        } catch (RuntimeException $e) {
            // just ignore for now
        }

        return null;
    }
318651
public function upload($imageFile)
    {
        if ($imageFile instanceof UploadedFile) {
            if ($imageFile->isValid()) {
                $pictureId = $this->pictureIdGenerator->generate($imageFile);
                if(false === $this->disk->putFileAs('', $imageFile, $this->pictureUrlManager->getOriginalPath($pictureId))){
                    throw new UploadException();
                }
                return $pictureId;
            } else {
                throw new UploadException($imageFile->getErrorMessage());
            }
        } else {
            throw new UploadException();
        }
    }
79730
private function _createFile($pFile)
    {
        $pathInfo = pathinfo($pFile);

        $dir = $pathInfo['dirname'];
        if (! DirecoryData::create($dir)) {
            throw new Exception("Unable to create the cache directory '$dir'");
        }

        if (! is_readable($pFile) and ! FileData::create($pFile, self::DEFAULT_CONTENT)) {
            throw new Exception("Unable to create the cache file '$pFile'");
        }

        return $this;
    }