Skip to content
This repository has been archived by the owner on Sep 11, 2024. It is now read-only.

Commit

Permalink
ImageResizer With Custom Urls Original Key
Browse files Browse the repository at this point in the history
  • Loading branch information
rankarpan committed May 20, 2018
1 parent 1d2ec19 commit b5a59cd
Showing 1 changed file with 15 additions and 8 deletions.
23 changes: 15 additions & 8 deletions src/ImageType.php
Original file line number Diff line number Diff line change
Expand Up @@ -191,13 +191,15 @@ public function url(string $filename = null, $sizes = [], $expirationTime = null
$this->expirationTime = empty($expirationTime) ? $this->expirationTime : $expirationTime;

if (empty($sizes) || in_array('original', $sizes)) {
$output = $this->typeConfig->get('original')['path'] . '/' . $filename['basename'];
$configOriginal = $this->typeConfig->get('original');
$output = $configOriginal['path'] . '/' . $filename['basename'];
$key = empty($configOriginal['as']) ? 'original' : $configOriginal['as'];

$storage = Storage::disk($this->originalFileDisk);
if ($this->originalDiskConfig['driver'] === 'local' || empty($this->typeConfig->get('original')['private'])) {
$urls['original'] = $storage->url($output);
if ($this->originalDiskConfig['driver'] === 'local' || empty($configOriginal['private'])) {
$urls[$key] = $storage->url($output);
} else {
$urls['original'] = $storage->temporaryUrl($output, Carbon::now()->addMinutes($this->expirationTime));
$urls[$key] = $storage->temporaryUrl($output, Carbon::now()->addMinutes($this->expirationTime));
}
}

Expand Down Expand Up @@ -226,8 +228,11 @@ public function temporaryUrl(string $filename = null, $sizes = [], $expirationTi
$this->expirationTime = empty($expirationTime) ? $this->expirationTime : $expirationTime;

if (empty($sizes) || in_array('original', $sizes)) {
$output = $this->typeConfig->get('original')['path'] . '/' . $filename['basename'];
$urls['original'] = Storage::disk($this->originalFileDisk)->temporaryUrl($output, Carbon::now()->addMinutes($this->expirationTime));
$configOriginal = $this->typeConfig->get('original');
$output = $configOriginal['path'] . '/' . $filename['basename'];
$key = empty($configOriginal['as']) ? 'original' : $configOriginal['as'];

$urls[$key] = Storage::disk($this->originalFileDisk)->temporaryUrl($output, Carbon::now()->addMinutes($this->expirationTime));
}

$configSizes = $this->typeConfig->get('sizes');
Expand Down Expand Up @@ -269,7 +274,9 @@ public function defaultUrl($sizes = [])
$defaultUrl = Storage::disk('local')->url($output);

if (empty($sizes) || in_array('original', $sizes)) {
$urls['original'] = $defaultUrl;
$configOriginal = $this->typeConfig->get('original');
$key = empty($configOriginal['as']) ? 'original' : $configOriginal['as'];
$urls[$key] = $defaultUrl;
}

$configSizes = $this->typeConfig->get('sizes');
Expand Down Expand Up @@ -310,7 +317,7 @@ protected function output($filename, $size, $dimensions)
{
if ($dimensions['extension'] === null) $dimensions['extension'] = $filename['extension'];

$fileSuffix = NULL;
$fileSuffix = null;

if ($this->baseFileSuffix) {
$fileSuffix = "-{$dimensions['width']}x{$dimensions['height']}";
Expand Down

0 comments on commit b5a59cd

Please sign in to comment.