Skip to content

Commit

Permalink
Reimplement longhand syntax for list() calls to reintroduce 7.0 compa…
Browse files Browse the repository at this point in the history
…tibility, only accepts arrays for options not iterable objects, support all absolute URLs (of the site) as relative files to the base_path()
  • Loading branch information
Bradie Tilley committed Jun 19, 2019
1 parent 3c90b89 commit 756cdb4
Showing 1 changed file with 12 additions and 12 deletions.
24 changes: 12 additions & 12 deletions classes/Resizer.php
Original file line number Diff line number Diff line change
Expand Up @@ -78,9 +78,9 @@ public function __construct(string $image)
public function setImage(string $image)
{
// Check if the image is an absolute url to the same server, if so get the storage path of the image
if (preg_match('/^(?:https?:\/\/)?' . $_SERVER['SERVER_NAME'] . '(?::\d+)?\/storage\/(.+)$/', $image, $m)) {
if (preg_match('/^(?:https?:\/\/)?' . $_SERVER['SERVER_NAME'] . '(?::\d+)?\/(.+)$/', $image, $m)) {
// Convert spaces, not going to urldecode as it will mess with pluses
$image = storage_path(str_replace('%20', ' ', $m[1]));
$image = base_path(str_replace('%20', ' ', $m[1]));
}

// If the image is invalid, default to Image Not Found
Expand Down Expand Up @@ -144,10 +144,10 @@ public function initResource()
* Initialise the options - Maps options and uses default options as a base as well as
* setting the hash to be used for caching
*
* @param iterable $options
* @param array $options
* @return void
*/
private function initOptions(iterable $options = null)
private function initOptions(array $options = null)
{
if ($options !== null) {
// Allow options with key $k, in place of key $v
Expand Down Expand Up @@ -188,7 +188,7 @@ private function initOptions(iterable $options = null)
// Check to see if a filter is being used for this image
if (!empty($options['filter'])) {
// If options were passed then use them to override any filters used
$options = array_filter($options);
$options = array_filter((array) $options);
$this->override = array_merge($this->override, $options);

// Now find it
Expand Down Expand Up @@ -247,7 +247,7 @@ public function getPath()
private function storagePath()
{
// Get format from destination file (or original, if not specified)
[$mime, $format] = $this->detectFormat(true);
list($mime, $format) = $this->detectFormat(true);
return 'app/uploads/public/' . substr($this->hash, 0, 3) . '/' . substr($this->hash, 3, 3) . '/' . substr($this->hash, 6, 3) . '/thumb_' . $this->hash . '.' . $format;
}

Expand Down Expand Up @@ -296,10 +296,10 @@ public function setCache()
*
* @param integer $width
* @param integer $height
* @param iterable $options
* @param array $options
* @return string
*/
public function resize(int $width = null, int $height = null, iterable $options = null)
public function resize(int $width = null, int $height = null, array $options = null)
{
$width = ($width > 0) ? $width : null;
$height = ($height > 0) ? $height : null;
Expand Down Expand Up @@ -452,7 +452,7 @@ public function resize(int $width = null, int $height = null, iterable $options
}

// Get the format / mime to export to (either original, or overridden)
[$mime, $format] = $this->detectFormat(true);
list($mime, $format) = $this->detectFormat(true);

// If it's exporting to a flat image and no background is set, and it was transparent to start off with..
if (($format !== 'png') && ($format !== 'webp') && empty($this->options['background']) && $this->detectAlpha()) {
Expand Down Expand Up @@ -526,7 +526,7 @@ private function detectFormat(bool $useNewFormat = false)
private function detectAlpha()
{
// Get source file's format
[$mime, $format] = $this->detectFormat();
list($mime, $format) = $this->detectFormat();

switch ($format) {
case 'png':
Expand Down Expand Up @@ -639,7 +639,7 @@ public function modify()
$this->im = Image::canvas($this->im->width(), $this->im->height(), $value)->insert($this->im);
break;
case 'colorize':
[$r, $g, $b] = explode(',', $value);
list($r, $g, $b) = explode(',', $value);
$this->im->colorize($r, $g, $b);
break;
default:
Expand All @@ -660,7 +660,7 @@ public function modify()
* @return void
*/
public function render() {
[$mime, $format] = $this->detectFormat(true);
list($mime, $format) = $this->detectFormat(true);

header('Content-Type: image/' . $mime);
echo $this->im->encode($format);
Expand Down

0 comments on commit 756cdb4

Please sign in to comment.