lucajackal85 /
ImageMerge
| 1 | <?php |
||||
| 2 | |||||
| 3 | namespace Jackal\ImageMerge\Command\Effect; |
||||
| 4 | |||||
| 5 | use Jackal\ImageMerge\Builder\ImageBuilder; |
||||
| 6 | use Jackal\ImageMerge\Command\AbstractCommand; |
||||
| 7 | use Jackal\ImageMerge\Command\Options\DimensionCommandOption; |
||||
| 8 | use Jackal\ImageMerge\Model\Image; |
||||
| 9 | |||||
| 10 | class CropOuter extends AbstractCommand |
||||
| 11 | { |
||||
| 12 | /** |
||||
| 13 | * CropOuter constructor. |
||||
| 14 | * @param DimensionCommandOption $options |
||||
| 15 | */ |
||||
| 16 | public function __construct(DimensionCommandOption $options) |
||||
| 17 | { |
||||
| 18 | parent::__construct($options); |
||||
| 19 | } |
||||
| 20 | |||||
| 21 | /** |
||||
| 22 | * @param Image $image |
||||
| 23 | * @return Image |
||||
| 24 | */ |
||||
| 25 | public function execute(Image $image) |
||||
| 26 | { |
||||
| 27 | $newWidth = $this->options->getDimention()->getWidth(); |
||||
|
0 ignored issues
–
show
Bug
introduced
by
Loading history...
|
|||||
| 28 | $newHeight = $this->options->getDimention()->getHeight(); |
||||
| 29 | |||||
| 30 | $thumbAspect = $newWidth / $newHeight; |
||||
| 31 | $builder = new ImageBuilder($image); |
||||
| 32 | if ($image->getAspectRatio() >= $thumbAspect) { |
||||
| 33 | $builder->resize($newWidth, null); |
||||
| 34 | } else { |
||||
| 35 | $builder->resize(null, $newHeight); |
||||
| 36 | } |
||||
| 37 | |||||
| 38 | $posX = ($newWidth - $image->getWidth()) / 2; |
||||
| 39 | $posY = ($newHeight - $image->getHeight()) / 2; |
||||
| 40 | |||||
| 41 | $image_p = imagecreatetruecolor($newWidth, $newHeight); |
||||
| 42 | imagecopyresampled($image_p, $image->getResource(), $posX, $posY, 0, 0, $image->getWidth(), $image->getHeight(), $image->getWidth(), $image->getHeight()); |
||||
|
0 ignored issues
–
show
It seems like
$image_p can also be of type false; however, parameter $dst_image of imagecopyresampled() does only seem to accept resource, maybe add an additional type check?
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
Loading history...
|
|||||
| 43 | |||||
| 44 | $image->assignResource($image_p); |
||||
| 45 | |||||
| 46 | return $image; |
||||
| 47 | } |
||||
| 48 | } |
||||
| 49 |