Process a given image

@param  Image   $image
@param  string  $format
@param  int $quality
@return Image
764728
public function process(Image $image, $format = null, $quality = null)
    {
        $this->setImage($image);
        $this->setFormat($format);
        $this->setQuality($quality);

        switch (strtolower($this->format)) {

            case 'data-url':
                $this->result = $this->processDataUrl();
                break;

            case 'gif':
            case 'image/gif':
                $this->result = $this->processGif();
                break;

            case 'png':
            case 'image/png':
            case 'image/x-png':
                $this->result = $this->processPng();
                break;

            case 'jpg':
            case 'jpeg':
            case 'image/jpg':
            case 'image/jpeg':
            case 'image/pjpeg':
                $this->result = $this->processJpeg();
                break;

            case 'tif':
            case 'tiff':
            case 'image/tiff':
            case 'image/tif':
            case 'image/x-tif':
            case 'image/x-tiff':
                $this->result = $this->processTiff();
                break;

            case 'bmp':
            case 'ms-bmp':
            case 'x-bitmap':
            case 'x-bmp':
            case 'x-ms-bmp':
            case 'x-win-bitmap':
            case 'x-windows-bmp':
            case 'x-xbitmap':
            case 'image/bmp':
            case 'image/ms-bmp':
            case 'image/x-bitmap':
            case 'image/x-bmp':
            case 'image/x-ms-bmp':
            case 'image/x-win-bitmap':
            case 'image/x-windows-bmp':
            case 'image/x-xbitmap':
                $this->result = $this->processBmp();
                break;

            case 'ico':
            case 'image/x-ico':
            case 'image/x-icon':
            case 'image/vnd.microsoft.icon':
                $this->result = $this->processIco();
                break;

            case 'psd':
            case 'image/vnd.adobe.photoshop':
                $this->result = $this->processPsd();
                break;

            case 'webp':
            case 'image/webp':
            case 'image/x-webp':
                $this->result = $this->processWebp();
                break;
                
            default:
                throw new \Hail\Image\Exception\NotSupportedException(
                    "Encoding format ({$format}) is not supported."
                );
        }

        $this->setImage(null);

        return $image->setEncoded($this->result);
    }
546992
public static function image2Jpeg($file, $quality = 80)
    {
        try {
            if (is_file($file)) {
                return Image::open($file)->setCacheDir(dirname($file))->jpeg($quality);
            }
        } catch (Exception $e) {
        }
        return false;
    }
1192799
public function getJPEGImage($quality, $backgroundColor){

        if($this->owner->exists()) {

            $pathinfo = pathinfo($this->owner->Name);

            $cacheFile = $this->owner->cacheToJPEGFilename($quality, $backgroundColor, $pathinfo);

            list($width, $height, $type, $attr) = getimagesize($this->owner->getFullPath());


            if($type == IMAGETYPE_JPEG && $quality == 100) return $this->owner;

            if(!file_exists(Director::baseFolder()."/".$cacheFile) || isset($_GET['flush'])) {
                // convert the current file to jpeg
                $this->owner->generateToJPEGImage($quality, $backgroundColor, $pathinfo, $type);
            }

			if($this->owner instanceof SecureImage) $cached = new SecureImage_Cached($cacheFile);
			else $cached = new Image_Cached($cacheFile);

			// Pass through the title so the templates can use it
			$cached->Title = $this->owner->Title;
			$cached->ID = $this->owner->ID;
			$cached->ParentID = $this->owner->ParentID;
			return $cached;
		}
	}
928180
public function xhrFormatAction(Image $image, $formatName, Request $request)
    {
        // retrieve format value object
        if (!$format = $this->container->get('synapse.image_format.loader')
            ->retrieveOne(array('name' => $formatName))
        ) {
            return new JsonResponse(
                array(
                    'error' => 400,
                    'error_message' => sprintf('No format found with name "%s".', $formatName),
                ),
                400
            );
        }

        // form handle
        $form = $this->container->get('form.factory')->createNamed(
            '',
            FormatType::class,
            $image,
            array(
                'format' => $format,
                'method' => 'POST',
                'csrf_protection' => false,
            )
        );
        $form->handleRequest($request);
        if (!$form->isValid()) {
            return new JsonResponse(
                array(
                    'error' => 400,
                    'error_message' => 'Invalid format data.',
                ),
                400
            );
        }

        // formatted image data
        return new JsonResponse(
            $form->getData()
                ->getFormattedImage($formatName)
                ->normalize(),
            201
        );
    }
997599
public function getDominantColor($image, $quality, $colorValue)
    {
        try {
            $source = new LocalSourceImageModel($image);
            $source->getLocalCopy();
        } catch (ImagerException $e) {
            return null;
        }

        $dominantColor = ColorThief::getColor($source->getFilePath(), $quality);

        ImagerService::cleanSession();

        if (!\is_array($dominantColor)) {
            return null;
        }

        return $colorValue === 'hex' ? self::rgb2hex($dominantColor) : $dominantColor;
    }
741292
public function execute($image)
    {
        $format = $this->argument(0)->value();
        $quality = $this->argument(1)->between(0, 100)->value();

        $this->setOutput(\GuzzleHttp\Psr7\stream_for(
            $image->encode($format, $quality)->getEncoded()
        ));

        return true;
    }
672409
public function outputBase64($quality = null)
    {
        ob_start();
        $this->save(-1, $quality);
        $image_data = ob_get_contents();
        ob_end_clean();

        return 'data:' . $this->original_info['mime'] . ';base64,' . base64_encode($image_data);
    }
639673
public function output($image_type = null, $quality = null)
    {
        $image_type = $image_type ?: $this->source_type;

        header('Content-Type: ' . image_type_to_mime_type($image_type));

        $this->save(null, $image_type, $quality);
    }
566415
function output($format = null, $quality = null) {
        // Determine quality
        $quality = $quality ? : $this->quality;
        // Determine mimetype
        switch (strtolower($format)) {
            case 'gif':
                $mimetype = 'image/gif';
                break;
            case 'jpeg':
            case 'jpg':
                imageinterlace($this->image, true);
                $mimetype = 'image/jpeg';
                break;
            case 'png':
                $mimetype = 'image/png';
                break;
            default:
                $info = (empty($this->imagestring)) ? getimagesize($this->filename) : getimagesizefromstring($this->imagestring);
                $mimetype = $info['mime'];
                unset($info);
                break;
        }
        // Output the image
        header('Content-Type: ' . $mimetype);
        switch ($mimetype) {
            case 'image/gif':
                imagegif($this->image);
                break;
            case 'image/jpeg':
                imageinterlace($this->image, true);
                imagejpeg($this->image, null, round($quality));
                break;
            case 'image/png':
                imagepng($this->image, null, round(9 * $quality / 100));
                break;
            default:
                throw new Exception('Unsupported image format: ' . $this->filename);
                break;
        }
    }
805173
public static function create($files, $path, $quality = 0)
    {
        switch( self::getFileExtension($path) )
        {
            case 'png' : 
                if( $quality > 10 )
                {
                    $quality = (int) ($quality / 10);
                }
                return imagepng($files, $path, $quality ?: 8 );
            case 'gif' : return imagegif($files, $path);
            case 'jpg' :
            case 'jpeg': 
            default    : return imagejpeg($files, $path, $quality ?: 80);
        }
    }
1119086
public function process(Image $image, $command_line = '') {
        $result = new Result();

        $result->setCommandLine($command_line . ' -unsharp ' . escapeshellarg($this->radius . 'x' . $this->sigma . '+' . $this->gain . '+' . $this->threshold));

        return $result;
    }
1094941
protected function thumbnailResize(Image $image, $width, $height)
    {
        return $image->resize($width, $height, function ($constraint) {
            $constraint->aspectRatio();
        });
    }
283066
public function save($file = null, $quality = 90) {

		if(null !== $file && false === is_string($file)) {
			return trigger_error(sprintf('Argument 1 passed to %s() must be of the type string, "%s" given', __METHOD__, gettype($file)), E_USER_ERROR);
		}

		if(null !== $file && false === is_writable(dirname($file))) {
			return trigger_error(sprintf('File in "%s" directory is not writable', dirname($file)), E_USER_ERROR);
		}

		if(false === ('-' . intval($quality) == '-' . $quality)) {
			return trigger_error(sprintf('Argument 2 passed to %s() must be of the type integer, "%s" given', __METHOD__, gettype($quality)), E_USER_ERROR);
		}

		if($quality < 0 || $quality > 100) {
			return trigger_error(sprintf('Argument 2 passed to %s() must be between 0 and 100, "%s" given', __METHOD__, $quality), E_USER_ERROR);
		}

		foreach($this -> commands as $command) {
			$resource = call_user_func_array([$this -> call(), $command -> method], $command -> params);
		}

		switch(strtolower($this -> extension)) {

			case 'bmp'	: imagewbmp($resource, $file); break;
			case 'png'	: imagepng($resource, $file, $this -> getQuality($quality, $this -> extension)); break;
			case 'gif'	: imagegif($resource, $file); break;
			default 	: imagejpeg($resource, $file, $this -> getQuality($quality, $this -> extension)); break;
		}
	}
650226
public function rotateImage180(Image $file, $quality = 95)
	{
		$this->rotateImage($file, ImageProcessor\ImageRotator::ROTATE_180, $quality);
	}
773352
public function save($dst, $format = 'jpeg', $quality = 80): bool
    {
        $this->check();

        if (!$this->actionsPossible()) {
            throw new RuntimeException('Actions can not be applied.');
        }

        if (!$this->apply()) {
            return false;
        }

        switch (strtolower($format)) {
            case 'jpg':
            case 'jpeg':
                return imagejpeg($this->image_resource, $dst, $quality);

            case 'gif':
                return imagegif($this->image_resource, $dst);

            case 'png':
                return imagepng($this->image_resource, $dst, abs($quality / 10 - 10));

        }

        return false;
    }
913347
public function execute($image)
    {
        $format = $this->argument(0)->value();
        $quality = $this->argument(1)->between(0, 100)->value();

        $response = new Response($image, $format, $quality);

        $this->setOutput($response->make());

        return true;
    }
1170282
public function getImageAsString($image_type = null, $quality = null)
    {
        $string_temp = tempnam('', '');
        $this->save($string_temp, $image_type, $quality);
        $string = file_get_contents($string_temp);
        unlink($string_temp);
        
        return $string;
    }