-
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
added a way to load a data uri image
- Loading branch information
Showing
4 changed files
with
47 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
<?php | ||
|
||
namespace SergiX44\ImageZen\Drivers; | ||
|
||
trait DecodeDataUriImage | ||
{ | ||
|
||
public function isDataUriImage(string $string): bool | ||
{ | ||
return str_starts_with($string, 'data:image/'); | ||
} | ||
|
||
public function decodeDataUriImage(string $string): string | ||
{ | ||
if (!$this->isDataUriImage($string)) { | ||
return $string; | ||
} | ||
|
||
if (str_contains($string, ';base64,')) { | ||
return base64_decode(explode(';base64,', $string)[1]); | ||
} | ||
|
||
return urldecode(explode(',', $string)[1]); | ||
} | ||
} |
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