src/Server.php
public function makeImage($path, array $params)
    {
        $sourcePath = $this->getSourcePath($path);
        $cachedPath = $this->getCachePath($path, $params);

        if ($this->cacheFileExists($path, $params) === true) {
            return $cachedPath;
        }

        if ($this->sourceFileExists($path) === false) {
            throw new FileNotFoundException(
                'Could not find the image `'.$sourcePath.'`.'
            );
        }

        $source = $this->source->read(
            $sourcePath
        );

        if ($source === false) {
            throw new FilesystemException(
                'Could not read the image `'.$sourcePath.'`.'
            );
        }

        // We need to write the image to the local disk before
        // doing any manipulations. This is because EXIF data
        // can only be read from an actual file.
        $tmp = tempnam(sys_get_temp_dir(), 'Glide');

        if (file_put_contents($tmp, $source) === false) {
            throw new FilesystemException(
                'Unable to write temp file for `'.$sourcePath.'`.'
            );
        }

        try {
            $write = $this->cache->write(
                $cachedPath,
                $this->api->run($tmp, $this->getAllParams($params))
            );

            if ($write === false) {
                throw new FilesystemException(
                    'Could not write the image `'.$cachedPath.'`.'
                );
            }
        } catch (FileExistsException $exception) {
            // This edge case occurs when the target already exists
            // because it's currently be written to disk in another
            // request. It's best to just fail silently.
        } finally {
            unlink($tmp);
        }

        return $cachedPath;
    }
public function makeImage($path, array $params)
    {
        $sourcePath = $this->getSourcePath($path);
        $cachedPath = $this->getCachePath($path, $params);

        if ($this->cacheFileExists($path, $params) === true) {
            return $cachedPath;
        }

        if ($this->sourceFileExists($path) === false) {
            throw new FileNotFoundException(
                'Could not find the image `'.$sourcePath.'`.'
            );
        }

        $source = $this->source->read(
            $sourcePath
        );

        if ($source === false) {
            throw new FilesystemException(
                'Could not read the image `'.$sourcePath.'`.'
            );
        }

        // We need to write the image to the local disk before
        // doing any manipulations. This is because EXIF data
        // can only be read from an actual file.
        $tmp = tempnam(sys_get_temp_dir(), 'Glide');

        if (file_put_contents($tmp, $source) === false) {
            throw new FilesystemException(
                'Unable to write temp file for `'.$sourcePath.'`.'
            );
        }

        try {
            $write = $this->cache->write(
                $cachedPath,
                $this->api->run($tmp, $this->getAllParams($params))
            );

            if ($write === false) {
                throw new FilesystemException(
                    'Could not write the image `'.$cachedPath.'`.'
                );
            }
        } catch (FileExistsException $exception) {
            // This edge case occurs when the target already exists
            // because it's currently be written to disk in another
            // request. It's best to just fail silently.
        } finally {
            unlink($tmp);
        }

        return $cachedPath;
    }
public function makeImage ( $ path , array $ params ) { $ sourcePath = $ this -> getSourcePath ( $ path ) ; $ cachedPath = $ this -> getCachePath ( $ path , $ params ) ; if ( $ this -> cacheFileExists ( $ path , $ params ) === true ) { return $ cachedPath ; } if ( $ this -> sourceFileExists ( $ path ) === false ) { throw new FileNotFoundException ( 'Could not find the image `' . $ sourcePath . '`.' ) ; } $ source = $ this -> source -> read ( $ sourcePath ) ; if ( $ source === false ) { throw new FilesystemException ( 'Could not read the image `' . $ sourcePath . '`.' ) ; } // We need to write the image to the local disk before // doing any manipulations. This is because EXIF data // can only be read from an actual file. $ tmp = tempnam ( sys_get_temp_dir ( ) , 'Glide' ) ; if ( file_put_contents ( $ tmp , $ source ) === false ) { throw new FilesystemException ( 'Unable to write temp file for `' . $ sourcePath . '`.' ) ; } try { $ write = $ this -> cache -> write ( $ cachedPath , $ this -> api -> run ( $ tmp , $ this -> getAllParams ( $ params ) ) ) ; if ( $ write === false ) { throw new FilesystemException ( 'Could not write the image `' . $ cachedPath . '`.' ) ; } } catch ( FileExistsException $ exception ) { // This edge case occurs when the target already exists // because it's currently be written to disk in another // request. It's best to just fail silently. } finally { unlink ( $ tmp ) ; } return $ cachedPath ; }
Generate manipulated image.
@param  string                $path   Image path.
@param  array                 $params Image manipulation params.
@return string                Cache path.
@throws FileNotFoundException
@throws FilesystemException
Generate manipulated image .