Skip to content

Commit a236378

Browse files
authored
[TASK] Add getImageUrl to the image service (#23)
1 parent 584f4d9 commit a236378

1 file changed

Lines changed: 17 additions & 1 deletion

File tree

Classes/Services/CloudinaryImageService.php

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@
2626
*/
2727
class CloudinaryImageService extends AbstractCloudinaryMediaService
2828
{
29-
3029
/**
3130
* @var ExplicitDataCacheRepository
3231
*/
@@ -37,6 +36,13 @@ class CloudinaryImageService extends AbstractCloudinaryMediaService
3736
*/
3837
protected $storageRepository;
3938

39+
protected array $defaultOptions = [
40+
'type' => 'upload',
41+
'resource_type' => 'image',
42+
'fetch_format' => 'auto',
43+
'quality' => 'auto',
44+
];
45+
4046
/**
4147
*
4248
*/
@@ -154,6 +160,16 @@ public function max($items) {
154160
return max($items);
155161
}
156162

163+
public function getImageUrl(File $file, array $options = []): string
164+
{
165+
$options = array_merge($this->defaultOptions, $options);
166+
167+
$publicId = $this->getPublicIdForFile($file);
168+
169+
$this->initializeApi($file->getStorage());
170+
return \Cloudinary::cloudinary_url($publicId, $options);
171+
}
172+
157173
/**
158174
* @param array $breakpoints
159175
*

0 commit comments

Comments
 (0)