phpsa /
datastore
| 1 | <?php |
||
| 2 | namespace Phpsa\Datastore\Ams; |
||
| 3 | use Phpsa\Datastore\Asset; |
||
| 4 | |||
| 5 | use Illuminate\Support\Facades\Storage; |
||
| 6 | use Illuminate\Support\Facades\View; |
||
| 7 | use Intervention\Image\Facades\Image; |
||
| 8 | |||
| 9 | class ImageAsset extends Asset { |
||
| 10 | |||
| 11 | public $type = ImageAsset::class; |
||
| 12 | public $namespace = 'property'; |
||
| 13 | |||
| 14 | public static function getImageUrl($filename, $width = null, $height = null){ |
||
| 15 | |||
| 16 | $imagePath = public_path().'/vendor/phpsa-datastore/'; |
||
| 17 | |||
| 18 | if ($width || $height) { |
||
| 19 | $path = 'thumbs/' . $width . 'x' . $height . '.' . $filename; |
||
| 20 | |||
| 21 | if(!is_file($imagePath . $path)){ |
||
| 22 | try{ |
||
| 23 | Image::make(public_path().'/vendor/phpsa-datastore/img/' . $filename)->resize($width,$height, function ($constraint) { |
||
| 24 | $constraint->aspectRatio(); |
||
| 25 | })->save($imagePath . $path); |
||
| 26 | }catch(Exception $e){ |
||
|
0 ignored issues
–
show
Bug
introduced
by
Loading history...
|
|||
| 27 | //Silent fallback as the image does not exist! |
||
| 28 | } |
||
| 29 | } |
||
| 30 | }else{ |
||
| 31 | $path = 'img/' . $filename; |
||
| 32 | } |
||
| 33 | return '/vendor/phpsa-datastore/' . $path; |
||
| 34 | |||
| 35 | |||
| 36 | |||
| 37 | } |
||
| 38 | |||
| 39 | public static function html($data) { |
||
| 40 | |||
| 41 | return '<img src="' . self::getImageUrl($data['value']) . '" />'; |
||
| 42 | } |
||
| 43 | |||
| 44 | |||
| 45 | |||
| 46 | } |
||
| 47 |