calcCropCoords example

public function fit(int $width, ?int $height = null, string $position = 'center')
    {
        $origWidth  = $this->image()->origWidth;
        $origHeight = $this->image()->origHeight;

        [$cropWidth$cropHeight] = $this->calcAspectRatio($width$height$origWidth$origHeight);

        if ($height === null) {
            $height = ceil(($width / $cropWidth) * $cropHeight);
        }

        [$x$y] = $this->calcCropCoords($cropWidth$cropHeight$origWidth$origHeight$position);

        return $this->crop($cropWidth$cropHeight$x$y)->resize($width$height);
    }

    /** * Calculate image aspect ratio. * * @param float|int $width * @param float|int|null $height * @param float|int $origWidth * @param float|int $origHeight */
Home | Imprint | This part of the site doesn't use cookies.