Converts one frame of a video to an image using FFMPEG.

@param resource $resource

@return resource
481002
private function convertVideoToImage($resource)
    {
        $temporaryFilePath = $this->createTemporaryFile($resource);
        $this->videoThumbnail->generate($temporaryFilePath, '00:00:02:01', $temporaryFilePath);

        $extractedImage = file_get_contents($temporaryFilePath);
        unlink($temporaryFilePath);

        return $this->createTemporaryResource($extractedImage);
    }
1205677
public function save($resource, $destination)
    {
        if ($this->mime == 'image/gif') {
            return imagegif($resource, $destination);
        }
        elseif ($this->mime == 'image/jpg' || $this->mime == 'image/jpeg') {
            return imagejpeg($resource, $destination);
        }
        elseif ($this->mime == 'image/png') {
            return imagepng($resource, $destination);
        }
        else
            return false;
    }
1269947
protected function convertResourceToObject($resource, $resourceId = null)
    {
        return ! $resource instanceof Resource ? new SimpleResource($resource, $resourceId) : $resource;
    }
829468
protected function getOriginalFile($resource)
    {
        $file = null;
        $path = storage_path('app/' . $resource->path);

        if( ! File::exists($path) ) {
            HCLog::error('R-THUMB-001', 'File not found at path: ' . $path);
        } else if( $resource->isImage() || strpos($resource->mime_type, 'svg') !== false ) {
            $file = File::get($path);
        }

        return $file;
    }
392755
protected function makeRequest($resource)
    {
        $url = "{$this->api_url}/{$resource}";

        $response = $this->guzzle->get($url, $this->getHeaders())->getBody();

        return json_decode($response, true);
    }
429157
protected function handleResource($resource) {
		if ($resource instanceof Resource) {
			return $resource;
		}
		
		// Is not a local resource
		if (preg_match('~^[a-z]+:~', $resource)) {
			$slashPos = strrpos($resource, '/');
			
			$base = substr($resource, 0, $slashPos);
			$name = substr($resource, $slashPos + 1);
			
			$resource = new Resource($name, $base, $base, $this->metadataManager);
		} else {
			$resource = new Resource($resource, $this->basePath, $this->baseUrl, $this->metadataManager);
		}
		
		if ($this->hashAppend) {
			$resource->setHashAppend(true);
		}
		
		return $resource;
	}
22465
public static function create($resource)
    {
        $type = gettype($resource);

        if ($type == 'string') {
            $stream = fopen('php://temp', 'r+');

            if ($resource !== '') {
                fwrite($stream, $resource);
                fseek($stream, 0);
            }

            return new self($stream);
        }

        if ($type == 'resource') {
            return new self($resource);
        }

        if ($resource instanceof StreamableInterface) {
            return $resource;
        }

        throw new \InvalidArgumentException('Invalid resource type: ' . $type);
    }
1329564
public function getResourceUrl($resource)
    {
        Assert::oneOf(
            $resource,
            self::getResourcesNames(),
            'Resource type "%s" is not supported by the ACME server (supported: %2$s)'
        );

        return isset($this->serverResources[$resource]) ? $this->serverResources[$resource] : null;
    }
1313965
public static function toSerialize($resource) {
		if (!self::isArray($resource)) {
			$resource = self::toArray($resource);
		}

		return serialize($resource);
	}
1154288
public function apply($resource){
		@list(,$input,$output)=func_get_args();
		$input=(float)$input;
		$output=(float)$output;
		if(!imagegammacorrect($resource,$input,$output)){
			throw new Exception("Gamma correction failed");
		}
		return $resource;
	}
1045173
public function apply($resource){
		if(!function_exists('imagefilter')){
			throw new Exception("It seems your PHP version is not compiled with the bundled version of the GD library");
		}
		// Format
		@list(,$level)=func_get_args();
		$level=(int)$level;
		if($level<-255) $level=-255;
		if($level>255)  $level=255;
		// Apply effect
		if(!imagefilter($resource,IMG_FILTER_BRIGHTNESS,$level)){
			throw new Exception("BRIGHTNESS filter failed");
		}
		return $resource;
	}
188897
public function apply($resource){
		// Extract arguments
		@list(,$h,$s,$v,$a)=func_get_args();
		$h=(int)$h;
		$s=(int)$s;
		$v=(int)$v;
		$a=(int)$a;
		// Convert
		list($r,$g,$b)=hsv2rgb($h,$s,$v);
		// Normalize
		if($a<0)        $a=0;
		elseif($a>100)  $a=100;
		if($v<0)        $v=0;
		elseif($v>100)  $v=100;
		$a=(100-$a)*1.27;
		$v=($v*2-100)*2.55;
		// Compute hue ratio
		$delta=($r+$g+$b);
		if($delta!=0){
			$ratio1=$r/$delta;
			$ratio2=$g/$delta;
			$ratio3=$b/$delta;
		}
		// récupération de la résolution
		$width=imagesx($resource);
		$height=imagesy($resource);
		if(!$width || !$height){
			throw new Exception("An error was encountered while getting image resolution");
		}
		// Apply effect
		$x=0;
		do{
			$y=0;
			do{
				// Get current pixel color
				list($r,$g,$b)=$this->_getColorAt($resource,$x,$y);
				// Define new color
				$new_r=$r*$ratio1+$g*$ratio2+$b*$ratio3+$v;
				$new_g=$r*$ratio3+$g*$ratio1+$b*$ratio2+$v;
				$new_b=$r*$ratio2+$g*$ratio3+$b*$ratio1+$v;
				// Format
				if($new_r<0)        $new_r=0;
				elseif($new_r>255)  $new_r=255;
				if($new_g<0)        $new_g=0;
				elseif($new_g>255)  $new_g=255;
				if($new_b<0)        $new_b=0;
				elseif($new_b>255)  $new_b=255;
				// Define pixel
				imagesetpixel($resource,$x,$y,imagecolorallocatealpha($resource,$new_r,$new_g,$new_b,$a));
			}
			while(++$y<$height);
		}
		while(++$x<$width);
		return $resource;
	}
776679
protected function rewindStream($resource)
    {
        if (! Assert::resource($resource)) {
            throw new InvalidArgumentException(
                sprintf(
                    '%s::%s() parameter 1 must be "resource"',
                    __CLASS__,
                    __METHOD__
                )
            );
        }

        if (ftell($resource) !== 0 && $this->isSeekableStream($resource)) {
            rewind($resource);
        }
    }
875669
public function extractImage($source, $target, $start = '00:00:01', $frames = 1)
    {
        $this->serviceLocator->setShared('playgroundcore_phpvideotoolkit', false);
       
        $ffmpeg = $this->serviceLocator->get('playgroundcore_phpvideotoolkit')
            ->addPreInputCommand('-y');

        if (!empty($start)) {
            $ffmpeg->addPreInputCommand('-ss', $start);
        }

        $ffmpeg->addCommand('-i', $source)
            ->addCommand('-vframes', $frames)
            ->setOutputPath($target)
            ->execute();

        return $target;
    }
744529
public function apply($resource){
		// Verify support
		if(!function_exists('imagefilter')){
			throw new Exception("It seems your PHP version is not compiled with the bundled version of the GD library");
		}
		// Extract arguments
		@list(,$method)=func_get_args();
		// Apply effect
		switch($method){
			case self::GAUSSIAN:
				if(!imagefilter($resource,IMG_FILTER_GAUSSIAN_BLUR)){
					throw new Exception("GAUSSIAN_BLUR filter failed");
				}
				break;
			case self::SELECTIVE:
			default:
				if(!imagefilter($resource,IMG_FILTER_SELECTIVE_BLUR)){
					throw new Exception("SELECTIVE_BLUR filter failed");
				}
		}
		return $resource;
	}
42108
public function gdResourceToTruecolor(&$resource)
    {
        $width = imagesx($resource);
        $height = imagesy($resource);

        // new canvas
        $canvas = imagecreatetruecolor($width, $height);

        // fill with transparent color
        imagealphablending($canvas, false);
        $transparent = imagecolorallocatealpha($canvas, 255, 255, 255, 127);
        imagefilledrectangle($canvas, 0, 0, $width, $height, $transparent);
        imagecolortransparent($canvas, $transparent);
        imagealphablending($canvas, true);

        // copy original
        imagecopy($canvas, $resource, 0, 0, 0, 0, $width, $height);
        imagedestroy($resource);

        $resource = $canvas;

        return true;
    }
41619
protected function loadResource($resource)
    {
        $stream = fopen($resource, 'r');

        $stat = fstat($stream);

        if ($stat['size'] < self::MO_HEADER_SIZE) {
            throw new InvalidResourceException('MO stream content has an invalid format.');
        }
        $magic = unpack('V1', fread($stream, 4));
        $magic = hexdec(substr(dechex(current($magic)), -8));

        if (self::MO_LITTLE_ENDIAN_MAGIC == $magic) {
            $isBigEndian = false;
        } elseif (self::MO_BIG_ENDIAN_MAGIC == $magic) {
            $isBigEndian = true;
        } else {
            throw new InvalidResourceException('MO stream content has an invalid format.');
        }

        // formatRevision
        $this->readLong($stream, $isBigEndian);
        $count = $this->readLong($stream, $isBigEndian);
        $offsetId = $this->readLong($stream, $isBigEndian);
        $offsetTranslated = $this->readLong($stream, $isBigEndian);
        // sizeHashes
        $this->readLong($stream, $isBigEndian);
        // offsetHashes
        $this->readLong($stream, $isBigEndian);

        $messages = [];

        for ($i = 0; $i < $count; ++$i) {
            $pluralId = null;
            $translated = null;

            fseek($stream, $offsetId + $i * 8);

            $length = $this->readLong($stream, $isBigEndian);
            $offset = $this->readLong($stream, $isBigEndian);

            if ($length < 1) {
                continue;
            }

            fseek($stream, $offset);
            $singularId = fread($stream, $length);

            if (false !== strpos($singularId, "\000")) {
                list($singularId, $pluralId) = explode("\000", $singularId);
            }

            fseek($stream, $offsetTranslated + $i * 8);
            $length = $this->readLong($stream, $isBigEndian);
            $offset = $this->readLong($stream, $isBigEndian);

            if ($length < 1) {
                continue;
            }

            fseek($stream, $offset);
            $translated = fread($stream, $length);

            if (false !== strpos($translated, "\000")) {
                $translated = explode("\000", $translated);
            }

            $ids = ['singular' => $singularId, 'plural' => $pluralId];
            $item = compact('ids', 'translated');

            if (\is_array($item['translated'])) {
                $messages[$item['ids']['singular']] = stripcslashes($item['translated'][0]);
                if (isset($item['ids']['plural'])) {
                    $plurals = [];
                    foreach ($item['translated'] as $plural => $translated) {
                        $plurals[] = sprintf('{%d} %s', $plural, $translated);
                    }
                    $messages[$item['ids']['plural']] = stripcslashes(implode('|', $plurals));
                }
            } elseif (!empty($item['ids']['singular'])) {
                $messages[$item['ids']['singular']] = stripcslashes($item['translated']);
            }
        }

        fclose($stream);

        return array_filter($messages);
    }