HEX
Server: LiteSpeed
System: Linux srv1.dhviews.com 5.14.0-570.23.1.el9_6.x86_64 #1 SMP PREEMPT_DYNAMIC Tue Jun 24 11:27:16 EDT 2025 x86_64
User: bdedition (1723)
PHP: 7.4.33
Disabled: NONE
Upload Files
File: //home/bdedition/www/core/vendor/intervention/image/src/Modifiers/RemoveAnimationModifier.php
<?php

declare(strict_types=1);

namespace Intervention\Image\Modifiers;

use Intervention\Image\Drivers\SpecializableModifier;
use Intervention\Image\Exceptions\InputException;
use Intervention\Image\Exceptions\RuntimeException;
use Intervention\Image\Interfaces\FrameInterface;
use Intervention\Image\Interfaces\ImageInterface;

class RemoveAnimationModifier extends SpecializableModifier
{
    public function __construct(public int|string $position = 0)
    {
    }

    /**
     * @throws RuntimeException
     */
    public function chosenFrame(ImageInterface $image, int|string $position): FrameInterface
    {
        if (is_int($position)) {
            return $image->core()->frame($position);
        }

        if (preg_match("/^(?P<percent>[0-9]{1,3})%$/", $position, $matches) != 1) {
            throw new InputException(
                'Position must be either integer or a percent value as string.'
            );
        }

        $total = count($image);
        $position = intval(round($total / 100 * intval($matches['percent'])));
        $position = $position == $total ? $position - 1 : $position;

        return $image->core()->frame($position);
    }
}