-
-
Notifications
You must be signed in to change notification settings - Fork 1.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add percent values as input for ImageInterface::removeAnimation()
- Loading branch information
1 parent
8f73dd8
commit a299100
Showing
8 changed files
with
70 additions
and
34 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
29 changes: 29 additions & 0 deletions
29
src/Drivers/Abstract/Modifiers/AbstractRemoveAnimationModifier.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
<?php | ||
|
||
namespace Intervention\Image\Drivers\Abstract\Modifiers; | ||
|
||
use Intervention\Image\Exceptions\InputException; | ||
use Intervention\Image\Interfaces\FrameInterface; | ||
use Intervention\Image\Interfaces\ModifierInterface; | ||
|
||
abstract class AbstractRemoveAnimationModifier implements ModifierInterface | ||
{ | ||
protected function chosenFrame($image, int|string $position): FrameInterface | ||
{ | ||
if (is_int($position)) { | ||
return $image->frame($position); | ||
} | ||
|
||
if (preg_match("/^(?P<percent>[0-9]{1,3})%$/", $position, $matches) != 1) { | ||
throw new InputException( | ||
'Input value of Image::removeAnimation() 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->frame($position); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
<?php | ||
|
||
namespace Intervention\Image\Exceptions; | ||
|
||
class InputException extends \RuntimeException | ||
{ | ||
// | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters