Skip to content

Commit 91ea2d3

Browse files
committed
Add option to pass options
1 parent 36de2b8 commit 91ea2d3

File tree

2 files changed

+47
-2
lines changed

2 files changed

+47
-2
lines changed

src/FlysystemCloudinaryAdapter.php

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
use Cloudinary\Asset\Media;
1111
use Cloudinary\Cloudinary;
1212
use Cloudinary\Configuration\Configuration;
13+
use Cloudinary\Transformation\Resize;
1314
use CodebarAg\FlysystemCloudinary\Events\FlysystemCloudinaryResponseLog;
1415
use Exception;
1516
use Illuminate\Http\Client\RequestException;
@@ -520,12 +521,26 @@ private function extractExtraMetadata(array $metadata): array
520521
return $extracted;
521522
}
522523

523-
public function getUrl(string $path): string|false
524+
/**
525+
* Get the URL of an image with optional transformation parameters
526+
*
527+
* @param string|array $path
528+
* @return string
529+
*/
530+
531+
public function getUrl(string|array $path): string|false
524532
{
533+
$options = [];
534+
535+
if (is_array($path)) {
536+
$options = $path['options'] ?? [];
537+
$path = $path['path'];
538+
}
539+
525540
$path = $this->ensureFolderIsPrefixed(trim($path, '/'));
526541

527542
try {
528-
return (string) $this->cloudinary->image($path)->toUrl();
543+
return (string) $this->cloudinary->image($path)->toUrl(implode(',', $options));
529544
} catch (NotFound) {
530545
return false;
531546
}

tests/Feature/AdapterTest.php

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -323,3 +323,33 @@
323323
expect($url)->toContain('http://', '::path::')
324324
->not->toContain('https://');
325325
});
326+
327+
it('can get url with option', function () {
328+
// Secure URL
329+
330+
$cloudinary = new Cloudinary([
331+
'cloud_name' => env('CLOUDINARY_CLOUD_NAME'),
332+
'api_key' => env('CLOUDINARY_API_KEY'),
333+
'api_secret' => env('CLOUDINARY_API_SECRET'),
334+
'url' => [
335+
'secure' => true,
336+
],
337+
]);
338+
339+
$adapter = new FlysystemCloudinaryAdapter($cloudinary);
340+
341+
$url = $adapter->getUrl([
342+
'path' => '::path::',
343+
'options' => [
344+
'w_64',
345+
'h_64',
346+
'c_fill',
347+
'auto',
348+
],
349+
]);
350+
351+
expect($url)
352+
->toContain('https://', '::path::')
353+
->toContain('w_64', 'h_64', 'c_fill', 'auto')
354+
->not->toContain('http://');
355+
});

0 commit comments

Comments
 (0)