Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Implement image resolution management
- Loading branch information
1 parent
a445ef3
commit 0f846ce
Showing
14 changed files
with
202 additions
and
0 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
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,23 @@ | ||
<?php | ||
|
||
namespace Intervention\Image\Drivers\Gd\Modifiers; | ||
|
||
use Intervention\Image\Interfaces\ImageInterface; | ||
use Intervention\Image\Interfaces\ModifierInterface; | ||
|
||
class ResolutionModifier implements ModifierInterface | ||
{ | ||
public function __construct(protected float $x, protected float $y) | ||
{ | ||
// | ||
} | ||
|
||
public function apply(ImageInterface $image): ImageInterface | ||
{ | ||
foreach ($image as $frame) { | ||
imageresolution($frame->core(), $this->x, $this->y); | ||
} | ||
|
||
return $image; | ||
} | ||
} |
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,26 @@ | ||
<?php | ||
|
||
namespace Intervention\Image\Drivers\Imagick\Modifiers; | ||
|
||
use Intervention\Image\Interfaces\ImageInterface; | ||
use Intervention\Image\Interfaces\ModifierInterface; | ||
use Intervention\Image\Drivers\Imagick\Image; | ||
use Intervention\Image\Traits\CanCheckType; | ||
|
||
class ResolutionModifier implements ModifierInterface | ||
{ | ||
use CanCheckType; | ||
|
||
public function __construct(protected float $x, protected float $y) | ||
{ | ||
// | ||
} | ||
|
||
public function apply(ImageInterface $image): ImageInterface | ||
{ | ||
$imagick = $this->failIfNotClass($image, Image::class)->getImagick(); | ||
$imagick->setImageResolution($this->x, $this->y); | ||
|
||
return $image; | ||
} | ||
} |
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,9 @@ | ||
<?php | ||
|
||
namespace Intervention\Image\Interfaces; | ||
|
||
interface ResolutionInterface | ||
{ | ||
public function x(): float; | ||
public function y(): float; | ||
} |
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,23 @@ | ||
<?php | ||
|
||
namespace Intervention\Image; | ||
|
||
use Intervention\Image\Interfaces\ResolutionInterface; | ||
|
||
class Resolution implements ResolutionInterface | ||
{ | ||
public function __construct(protected float $x, protected float $y) | ||
{ | ||
// | ||
} | ||
|
||
public function x(): float | ||
{ | ||
return $this->x; | ||
} | ||
|
||
public function y(): float | ||
{ | ||
return $this->y; | ||
} | ||
} |
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,26 @@ | ||
<?php | ||
|
||
namespace Intervention\Image\Tests\Drivers\Gd\Modifiers; | ||
|
||
use Intervention\Image\Drivers\Gd\Modifiers\ResolutionModifier; | ||
use Intervention\Image\Tests\TestCase; | ||
use Intervention\Image\Tests\Traits\CanCreateGdTestImage; | ||
|
||
/** | ||
* @requires extension gd | ||
* @covers \Intervention\Image\Drivers\Gd\Modifiers\ResolutionModifier | ||
*/ | ||
class ResolutionModifierTest extends TestCase | ||
{ | ||
use CanCreateGdTestImage; | ||
|
||
public function testResolutionChange(): void | ||
{ | ||
$image = $this->createTestImage('test.jpg'); | ||
$this->assertEquals(72.0, $image->resolution()->x()); | ||
$this->assertEquals(72.0, $image->resolution()->y()); | ||
$image->modify(new ResolutionModifier(1, 2)); | ||
$this->assertEquals(1.0, $image->resolution()->x()); | ||
$this->assertEquals(2.0, $image->resolution()->y()); | ||
} | ||
} |
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
26 changes: 26 additions & 0 deletions
26
tests/Drivers/Imagick/Modifiers/ResolutionModifierTest.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,26 @@ | ||
<?php | ||
|
||
namespace Intervention\Image\Tests\Drivers\Imagick\Modifiers; | ||
|
||
use Intervention\Image\Drivers\Imagick\Modifiers\ResolutionModifier; | ||
use Intervention\Image\Tests\TestCase; | ||
use Intervention\Image\Tests\Traits\CanCreateImagickTestImage; | ||
|
||
/** | ||
* @requires extension gd | ||
* @covers \Intervention\Image\Drivers\Imagick\Modifiers\ResolutionModifier | ||
*/ | ||
class ResolutionModifierTest extends TestCase | ||
{ | ||
use CanCreateImagickTestImage; | ||
|
||
public function testResolutionChange(): void | ||
{ | ||
$image = $this->createTestImage('test.jpg'); | ||
$this->assertEquals(72.0, $image->resolution()->x()); | ||
$this->assertEquals(72.0, $image->resolution()->y()); | ||
$image->modify(new ResolutionModifier(1, 2)); | ||
$this->assertEquals(1.0, $image->resolution()->x()); | ||
$this->assertEquals(2.0, $image->resolution()->y()); | ||
} | ||
} |