-
-
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 functionality to add, remove and get color Profile data
- Loading branch information
1 parent
90a650e
commit 49a2e8a
Showing
6 changed files
with
176 additions
and
63 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
<?php | ||
|
||
namespace Intervention\Image\Colors; | ||
|
||
use Intervention\Image\GenericData; | ||
|
||
class Profile extends GenericData | ||
{ | ||
// | ||
} |
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,32 @@ | ||
<?php | ||
|
||
namespace Intervention\Image\Drivers\Imagick\Modifiers; | ||
|
||
use Intervention\Image\Colors\Profile; | ||
use Intervention\Image\Drivers\Imagick\Image; | ||
use Intervention\Image\Exceptions\ColorException; | ||
use Intervention\Image\Interfaces\ImageInterface; | ||
use Intervention\Image\Interfaces\ModifierInterface; | ||
use Intervention\Image\Traits\CanCheckType; | ||
|
||
class ProfileModifier implements ModifierInterface | ||
{ | ||
use CanCheckType; | ||
|
||
public function __construct(protected Profile $profile) | ||
{ | ||
// | ||
} | ||
|
||
public function apply(ImageInterface $image): ImageInterface | ||
{ | ||
$imagick = $this->failIfNotClass($image, Image::class)->getImagick(); | ||
$result = $imagick->profileImage('icc', (string) $this->profile); | ||
|
||
if ($result === false) { | ||
throw new ColorException('ICC color profile could not be set.'); | ||
} | ||
|
||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
<?php | ||
|
||
namespace Intervention\Image\Drivers\Imagick\Modifiers; | ||
|
||
use Intervention\Image\Drivers\Imagick\Image; | ||
use Intervention\Image\Exceptions\ColorException; | ||
use Intervention\Image\Interfaces\ImageInterface; | ||
use Intervention\Image\Interfaces\ModifierInterface; | ||
use Intervention\Image\Traits\CanCheckType; | ||
|
||
class ProfileRemovalModifier implements ModifierInterface | ||
{ | ||
use CanCheckType; | ||
|
||
public function apply(ImageInterface $image): ImageInterface | ||
{ | ||
$imagick = $this->failIfNotClass($image, Image::class)->getImagick(); | ||
$result = $imagick->profileImage('icc', null); | ||
|
||
if ($result === false) { | ||
throw new ColorException('ICC color profile could not be removed.'); | ||
} | ||
|
||
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,78 @@ | ||
<?php | ||
|
||
namespace Intervention\Image; | ||
|
||
use Intervention\Image\Exceptions\NotWritableException; | ||
|
||
class GenericData | ||
{ | ||
/** | ||
* Create new instance | ||
* | ||
* @param string $data | ||
*/ | ||
public function __construct(protected string $data) | ||
{ | ||
// | ||
} | ||
|
||
/** | ||
* Save encoded image data in file system | ||
* | ||
* @param string $filepath | ||
* @return void | ||
*/ | ||
public function save(string $filepath): void | ||
{ | ||
$saved = @file_put_contents($filepath, (string) $this); | ||
if ($saved === false) { | ||
throw new NotWritableException( | ||
"Can't write image data to path ({$filepath})." | ||
); | ||
} | ||
} | ||
|
||
/** | ||
* Cast encoded image object to string | ||
* | ||
* @return string | ||
*/ | ||
public function toString(): string | ||
{ | ||
return $this->data; | ||
} | ||
|
||
/** | ||
* Create file pointer from encoded image | ||
* | ||
* @return resource | ||
*/ | ||
public function toFilePointer() | ||
{ | ||
$pointer = fopen('php://temp', 'rw'); | ||
fputs($pointer, $this->toString()); | ||
rewind($pointer); | ||
|
||
return $pointer; | ||
} | ||
|
||
/** | ||
* Return byte size of encoded image | ||
* | ||
* @return int | ||
*/ | ||
public function size(): int | ||
{ | ||
return mb_strlen($this->data); | ||
} | ||
|
||
/** | ||
* Cast encoded image object to string | ||
* | ||
* @return string | ||
*/ | ||
public function __toString(): string | ||
{ | ||
return $this->toString(); | ||
} | ||
} |