-
-
Notifications
You must be signed in to change notification settings - Fork 224
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
TASK: Calculate a preliminary crop to the target aspect for images wi…
…th focalPoint The calculation of the preliminary crop ensures: 1. The crop to the target dimension is as large as possible inside the original image dimensions 2. The crop is placed in a way to ensure the focal point is as central as possible inside the original image dimensions
- Loading branch information
Showing
8 changed files
with
412 additions
and
14 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
94 changes: 94 additions & 0 deletions
94
Neos.Media/Classes/Domain/Model/Adjustment/MarkPointAdjustment.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,94 @@ | ||
<?php | ||
declare(strict_types=1); | ||
|
||
namespace Neos\Media\Domain\Model\Adjustment; | ||
|
||
/* | ||
* This file is part of the Neos.Media package. | ||
* | ||
* (c) Contributors of the Neos Project - www.neos.io | ||
* | ||
* This package is Open Source Software. For the full copyright and license | ||
* information, please view the LICENSE file which was distributed with this | ||
* source code. | ||
*/ | ||
|
||
use Imagine\Image\ImageInterface as ImagineImageInterface; | ||
use Imagine\Image\Point; | ||
use Neos\Flow\Annotations as Flow; | ||
use Imagine\Image\Palette; | ||
|
||
/** | ||
* An adjustment to draw on circle on an image | ||
* this is solely for debugging of focal points | ||
* @todo remove before merging | ||
* | ||
* @deprecated | ||
* @Flow\Entity | ||
*/ | ||
class MarkPointAdjustment extends AbstractImageAdjustment | ||
{ | ||
protected $position = 99; | ||
|
||
protected int $x; | ||
|
||
protected int $y; | ||
|
||
protected int $radius; | ||
|
||
protected int $thickness = 1; | ||
|
||
protected string $color = '#000'; | ||
|
||
|
||
public function setX(int $x): void | ||
{ | ||
$this->x = $x; | ||
} | ||
|
||
public function setY(int $y): void | ||
{ | ||
$this->y = $y; | ||
} | ||
|
||
public function setRadius(int $radius): void | ||
{ | ||
$this->radius = $radius; | ||
} | ||
|
||
public function setThickness(int $thickness): void | ||
{ | ||
$this->thickness = $thickness; | ||
} | ||
|
||
public function setColor(string $color): void | ||
{ | ||
$this->color = $color; | ||
} | ||
|
||
|
||
public function applyToImage(ImagineImageInterface $image) | ||
{ | ||
$palette = new Palette\RGB(); | ||
$color = $palette->color($this->color); | ||
$image->draw() | ||
->circle( | ||
new Point($this->x, $this->y), | ||
$this->radius, | ||
$color, | ||
false, | ||
$this->thickness | ||
) | ||
; | ||
|
||
return $image; | ||
} | ||
|
||
public function canBeApplied(ImagineImageInterface $image) | ||
{ | ||
if (is_null($this->x) || is_null($this->y) || is_null($this->radius)) { | ||
return false; | ||
} | ||
return true; | ||
} | ||
} |
27 changes: 27 additions & 0 deletions
27
Neos.Media/Classes/Domain/Model/Dto/PreliminaryCropSpecification.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,27 @@ | ||
<?php | ||
declare(strict_types=1); | ||
|
||
namespace Neos\Media\Domain\Model\Dto; | ||
|
||
/* | ||
* This file is part of the Neos.Media package. | ||
* | ||
* (c) Contributors of the Neos Project - www.neos.io | ||
* | ||
* This package is Open Source Software. For the full copyright and license | ||
* information, please view the LICENSE file which was distributed with this | ||
* source code. | ||
*/ | ||
|
||
use Imagine\Image\BoxInterface; | ||
use Imagine\Image\PointInterface; | ||
|
||
final readonly class PreliminaryCropSpecification | ||
{ | ||
public function __construct( | ||
public PointInterface $cropOffset, | ||
public BoxInterface $cropDimensions, | ||
public PointInterface $focalPoint, | ||
) { | ||
} | ||
} |
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
Oops, something went wrong.