| Conditions | 5 |
| Paths | 4 |
| Total Lines | 20 |
| Code Lines | 12 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 0 | ||
| 1 | <?php |
||
| 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){ |
||
|
|
|||
| 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 | |||
| 47 |