Skip to content

Commit 690c3c9

Browse files
committed
Fix CdnThumbnail URLs to match new ImageKit API
1 parent 33f3612 commit 690c3c9

File tree

1 file changed

+17
-13
lines changed

1 file changed

+17
-13
lines changed

src/Support/Thumbnails/CdnThumbnail.php

Lines changed: 17 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -6,32 +6,36 @@ class CdnThumbnail extends Thumbnail
66
{
77
public function make(?int $width, ?int $height = null, bool $fit = false): ?string
88
{
9-
return sprintf(
10-
'%s%s/storage/%s',
11-
config('ozu-client.cdn_url'),
12-
$this->generateUrlParameters($width, $height, $fit),
13-
$this->mediaModel->file_name
14-
);
9+
if($cdnUrl = str(config('ozu-client.cdn_url'))->rtrim('/')) {
10+
return sprintf(
11+
'%s/storage/%s?%s',
12+
$cdnUrl,
13+
$this->mediaModel->file_name,
14+
$this->generateUrlParameters($width, $height, $fit),
15+
);
16+
}
17+
18+
return null;
1519
}
1620

1721
private function generateUrlParameters(?int $width, ?int $height, bool $fit): string
1822
{
1923
if (!$fit) {
2024
if ($width && $height) {
21-
return sprintf('tr:w-%s,h-%s,c-at_max', $width, $height);
25+
return sprintf('tr=w-%s,h-%s,c-at_max', $width, $height);
2226
}
23-
if ($width) {
24-
return sprintf('tr:w-%s', $width);
25-
}
26-
return sprintf('tr:h-%s', $height ?: 400);
27+
28+
return $width
29+
? sprintf('tr=w-%s', $width)
30+
: sprintf('tr=h-%s', $height ?: 400);
2731
}
2832

2933
if ($width && $height) {
30-
return sprintf('tr:w-%s,h-%s,c-at_max', $width, $height);
34+
return sprintf('tr=w-%s,h-%s,c-at_max', $width, $height);
3135
}
3236

3337
$side = ($width ?: $height) ?: 400;
3438

35-
return sprintf('tr:w-%s,h-%s,c-maintain_ratio', $side, $side);
39+
return sprintf('tr=w-%s,h-%s,c-maintain_ratio', $side, $side);
3640
}
3741
}

0 commit comments

Comments
 (0)