Created
March 18, 2015 04:16
-
-
Save alchemydigital/2e3a2b7261e36003e42f to your computer and use it in GitHub Desktop.
Class to extend the Glide Server and enable correct auto-orientation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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