-
-
Notifications
You must be signed in to change notification settings - Fork 223
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 preliminary crop ensures: 1. The target image is as large as possible inside the original image dimensions 2. The focal point is as central as possible inside the generated image
- Loading branch information
Showing
9 changed files
with
453 additions
and
33 deletions.
There are no files selected for viewing
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; | ||
} | ||
} |
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
35 changes: 35 additions & 0 deletions
35
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,35 @@ | ||
<?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; | ||
use Neos\Flow\Annotations as Flow; | ||
|
||
/** | ||
* A DTO for storing the information for a preliminary in case a focal point is respected during thumbnail generation | ||
* plus the position of the focal point in the image after cropping and resizing | ||
* | ||
* @internal | ||
*/ | ||
#[Flow\Proxy(false)] | ||
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
Oops, something went wrong.