Skip to content

Instantly share code, notes, and snippets.

@alchemydigital
Created March 18, 2015 04:16
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save alchemydigital/2e3a2b7261e36003e42f to your computer and use it in GitHub Desktop.
Save alchemydigital/2e3a2b7261e36003e42f to your computer and use it in GitHub Desktop.
Class to extend the Glide Server and enable correct auto-orientation
<?php namespace Your\App\Namespace;
use League\Glide\Server as Glide;
use League\Glide\Http\NotFoundException;
class Server extends Glide {
public function makeImage()
{
$request = $this->resolveRequestObject(func_get_args());
if ($this->cacheFileExists($request) === true) {
return $request;
}
if ($this->sourceFileExists($request) === false) {
throw new NotFoundException(
'Could not find the image `'.$this->getSourcePath($request).'`.'
);
}
$source = $this->source->read(
$this->getSourcePath($request)
);
if ($source === false) {
throw new FilesystemException(
'Could not read the image `'.$this->getSourcePath($request).'`.'
);
}
/** New code */
$tmp = tempnam( sys_get_temp_dir(), '');
$handle = fopen($tmp, "w");
fwrite($handle, $source);
/* New code **/
try {
$write = $this->cache->write(
$this->getCachePath($request),
/** New code */
$this->api->run($request, $tmp)
/* New code **/
);
} catch (FileExistsException $exception) {
// Cache file failed to write. Fail silently.
/** New code */
unlink($tmp);
/* New code **/
return $request;
}
/** New code */
unlink($tmp);
/* New code **/
if ($write === false) {
throw new FilesystemException(
'Could not write the image `'.$this->getCachePath($request).'`.'
);
}
return $request;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment