File "CalculatesFocalCropCoordinates.php"
Full Path: /home/pulsehostuk9/public_html/invoicer.pulsehost.co.uk/vendor/spatie/image/src/Drivers/Concerns/CalculatesFocalCropCoordinates.php
File size: 1.01 KB
MIME-type: text/x-php
Charset: utf-8
<?php
namespace Spatie\Image\Drivers\Concerns;
/** @mixin \Spatie\Image\Drivers\ImageDriver */
trait CalculatesFocalCropCoordinates
{
/** @return array<int, int|null> */
protected function calculateFocalCropCoordinates(int $width, int $height, ?int $cropCenterX, ?int $cropCenterY): array
{
$width = min($width, $this->getWidth());
$height = min($height, $this->getHeight());
if ($cropCenterX > 0) {
$maxCropCenterX = $this->getWidth() - $width;
$cropCenterX = (int) ($cropCenterX - ($width / 2));
$cropCenterX = min($maxCropCenterX, $cropCenterX);
$cropCenterX = max(0, $cropCenterX);
}
if ($cropCenterY > 0) {
$maxCropCenterY = $this->getHeight() - $height;
$cropCenterY = (int) ($cropCenterY - ($height / 2));
$cropCenterY = min($maxCropCenterY, $cropCenterY);
$cropCenterY = max(0, $cropCenterY);
}
return [$width, $height, $cropCenterX, $cropCenterY];
}
}