raystech /
laravel-starter-kit
| 1 | <?php |
||
| 2 | |||
| 3 | namespace Raystech\StarterKit\Traits; |
||
| 4 | use Image; |
||
| 5 | |||
| 6 | trait ImageTrait |
||
| 7 | { |
||
| 8 | |||
| 9 | /* |
||
| 10 | |------------------------------------------------------------ |
||
| 11 | | @param mixed $image |
||
| 12 | | @param int $width |
||
| 13 | | @param int $height |
||
| 14 | | @param string $mode ['constrain', 'expand'] |
||
| 15 | | @param int $quality [0-100] |
||
| 16 | | |
||
| 17 | | @return \Intervention\Image\Image |
||
|
0 ignored issues
–
show
|
|||
| 18 | |------------------------------------------------------------ |
||
| 19 | */ |
||
| 20 | private function imageResize($image, $width, $height = null, $mode = 'expand', $quality = 85) { |
||
| 21 | if($height == null && $mode == 'expand') { |
||
|
0 ignored issues
–
show
|
|||
| 22 | $height = $width; |
||
| 23 | } |
||
| 24 | |||
| 25 | $img = Image::make($image->getRealPath()); |
||
| 26 | // $img = $image; |
||
| 27 | |||
| 28 | $margin = 0; |
||
| 29 | |||
| 30 | $img_width = $img->width(); |
||
| 31 | $img_height = $img->height(); |
||
| 32 | |||
| 33 | /* |
||
| 34 | * canvas |
||
| 35 | */ |
||
| 36 | $dimension = $width; |
||
| 37 | $desire_width = $width; |
||
| 38 | $desire_height = $height; |
||
| 39 | |||
| 40 | $vertical = ($img_width < $img_height); |
||
| 41 | $horizontal = ($img_width > $img_height); |
||
| 42 | $square = ($img_width = $img_height); |
||
|
0 ignored issues
–
show
|
|||
| 43 | |||
| 44 | if($mode == 'expand') { |
||
| 45 | if ($vertical) { |
||
| 46 | $top = $bottom = $margin; |
||
| 47 | $newHeight = ($dimension) - ($bottom + $top); |
||
| 48 | $img->resize(null, $newHeight, function ($constraint) { |
||
| 49 | $constraint->aspectRatio(); |
||
| 50 | }); |
||
| 51 | |||
| 52 | } else if ($horizontal) { |
||
| 53 | $right = $left = $margin; |
||
| 54 | $newWidth = ($dimension) - ($right + $left); |
||
| 55 | $img->resize($newWidth, null, function ($constraint) { |
||
| 56 | $constraint->aspectRatio(); |
||
| 57 | }); |
||
| 58 | |||
| 59 | } else if ($square) { |
||
| 60 | $right = $left = $margin; |
||
| 61 | $newWidth = ($dimension) - ($left + $right); |
||
| 62 | $img->resize($newWidth, null, function ($constraint) { |
||
| 63 | $constraint->aspectRatio(); |
||
| 64 | }); |
||
| 65 | |||
| 66 | } |
||
| 67 | |||
| 68 | $img->resizeCanvas($dimension, $dimension, 'center', false, '#ffffff'); |
||
| 69 | $img->encode('jpg', $quality); |
||
| 70 | |||
| 71 | } else if($mode == 'constrain') { |
||
| 72 | if ($vertical) { |
||
| 73 | $top = $bottom = $margin; |
||
| 74 | $newHeight = ($desire_height) - ($bottom + $top); |
||
| 75 | $img->resize(null, $newHeight, function ($constraint) { |
||
| 76 | $constraint->aspectRatio(); |
||
| 77 | }); |
||
| 78 | |||
| 79 | } else if ($horizontal) { |
||
| 80 | $right = $left = $margin; |
||
| 81 | $newWidth = ($desire_width) - ($right + $left); |
||
| 82 | $img->resize($newWidth, null, function ($constraint) { |
||
| 83 | $constraint->aspectRatio(); |
||
| 84 | }); |
||
| 85 | |||
| 86 | } else if ($square) { |
||
| 87 | $right = $left = $margin; |
||
| 88 | $newWidth = ($desire_width) - ($left + $right); |
||
| 89 | $img->resize($newWidth, null, function ($constraint) { |
||
| 90 | $constraint->aspectRatio(); |
||
| 91 | }); |
||
| 92 | |||
| 93 | } |
||
| 94 | |||
| 95 | $img->resizeCanvas($desire_width, $desire_height, 'center', false, '#ffffff'); |
||
| 96 | $img->encode('jpg', $quality); |
||
| 97 | } |
||
| 98 | |||
| 99 | |||
| 100 | return $img; |
||
| 101 | // $img->save(public_path("storage/{$token}/{$origFilename}")); |
||
| 102 | } |
||
| 103 | } |
The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g.
excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths