Skip to content

Commit 3912b58

Browse files
authored
Merge pull request #7 from Diewy/master
Fixed error 'Calling unknown method getThumbPath' in Craft 4
2 parents 093c30e + fed45d2 commit 3912b58

File tree

2 files changed

+23
-2
lines changed

2 files changed

+23
-2
lines changed

src/helpers/Thumbs.php

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
<?php
2+
3+
namespace kisonay\crafttwigimagebase64\helpers;
4+
5+
use craft\elements\Asset;
6+
use craft\models\ImageTransform;
7+
8+
class Thumbs
9+
{
10+
public static function getUrl(Asset $asset, $width = null, $height = null): string
11+
{
12+
$transform = new ImageTransform([
13+
'width' => $width,
14+
'height' => $height,
15+
'mode' => 'crop',
16+
]);
17+
18+
return $asset->getUrl($transform);
19+
}
20+
}

src/twigextensions/Crafttwigimagebase64TwigExtension.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
namespace kisonay\crafttwigimagebase64\twigextensions;
1212

1313
use kisonay\crafttwigimagebase64\Crafttwigimagebase64;
14+
use kisonay\crafttwigimagebase64\helpers\Thumbs as ThumbsHelper;
1415
use craft\elements\Asset;
1516

1617
use Craft;
@@ -98,7 +99,7 @@ public function image64($asset, $inline = false)
9899
// Return the string.
99100
return $inline ? sprintf('data:image/%s;base64,%s', $asset->getExtension(), base64_encode($binary)) : base64_encode($binary);
100101
}
101-
102+
102103
public function thumb64($asset, $width=100, $inline = false)
103104
{
104105
// Make sure it is an asset object
@@ -114,7 +115,7 @@ public function thumb64($asset, $width=100, $inline = false)
114115
}
115116

116117
// Get the file.
117-
$binary = file_get_contents(Craft::$app->getAssets()->getThumbPath($asset, $width));
118+
$binary = file_get_contents(ThumbsHelper::getUrl($asset, $width));
118119

119120
// Return the string.
120121
return $inline ? sprintf('data:image/%s;base64,%s', $asset->getExtension(), base64_encode($binary)) : base64_encode($binary);

0 commit comments

Comments
 (0)