generated from spatie/package-skeleton-php
-
-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
d8cfda8
commit 86b8cad
Showing
10 changed files
with
304 additions
and
143 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 |
---|---|---|
|
@@ -10,3 +10,5 @@ psalm.xml | |
vendor | ||
.php-cs-fixer.cache | ||
.DS_Store | ||
CHANGELOG-draft.md | ||
node_modules |
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,48 @@ | ||
<?php | ||
|
||
namespace Kiwilan\Ebook\Formats\Mobi\Parser; | ||
|
||
use Kiwilan\Ebook\Utils\Stream; | ||
|
||
class MobiImages | ||
{ | ||
protected function __construct( | ||
protected Stream $stream, | ||
protected array $items = [], | ||
) { | ||
} | ||
|
||
public static function make(string $path): ?self | ||
{ | ||
$self = new self(Stream::make($path)); | ||
|
||
$fileContent = $self->stream->read($self->stream->filesize()); | ||
$self->stream->close(); | ||
|
||
$regexJpg = '/\xff\xd8\xff.*?\xff\xd9/s'; | ||
if (preg_match_all($regexJpg, $fileContent, $matches)) { | ||
foreach ($matches[0] as $index => $imageData) { | ||
$self->items[] = base64_encode($imageData); | ||
} | ||
} | ||
|
||
return $self; | ||
} | ||
|
||
/** | ||
* @return string[] | ||
*/ | ||
public function getItems(bool $base64Decode = true): array | ||
{ | ||
if (! $base64Decode) { | ||
return $this->items; | ||
} | ||
|
||
$data = []; | ||
foreach ($this->items as $item) { | ||
$data[] = base64_decode($item); | ||
} | ||
|
||
return $data; | ||
} | ||
} |
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.