HEX
Server: Apache/2.4.58 (Ubuntu)
System: Linux ip-172-26-0-120 6.17.0-1009-aws #9~24.04.2-Ubuntu SMP Fri Mar 6 23:50:29 UTC 2026 x86_64
User: ubuntu (1000)
PHP: 8.3.6
Disabled: NONE
Upload Files
File: /var/www/html/orbidirectory.com/vendor/spatie/image/src/Drivers/Concerns/CalculatesCropOffsets.php
<?php

namespace Spatie\Image\Drivers\Concerns;

use Spatie\Image\Enums\CropPosition;

/** @mixin \Spatie\Image\Drivers\ImageDriver */
trait CalculatesCropOffsets
{
    /** @return array<int> */
    protected function calculateCropOffsets(int $width, int $height, CropPosition $position): array
    {
        [$offsetPercentageX, $offsetPercentageY] = $position->offsetPercentages();

        $offsetX = (int) (($this->getWidth() * $offsetPercentageX / 100) - ($width / 2));
        $offsetY = (int) (($this->getHeight() * $offsetPercentageY / 100) - ($height / 2));

        $maxOffsetX = $this->getWidth() - $width;
        $maxOffsetY = $this->getHeight() - $height;

        if ($offsetX < 0) {
            $offsetX = 0;
        }

        if ($offsetY < 0) {
            $offsetY = 0;
        }

        if ($offsetX > $maxOffsetX) {
            $offsetX = $maxOffsetX;
        }

        if ($offsetY > $maxOffsetY) {
            $offsetY = $maxOffsetY;
        }

        return [$offsetX, $offsetY];
    }
}