diff options
author | Mario <mario@mariovavti.com> | 2024-11-09 10:24:26 +0000 |
---|---|---|
committer | Mario <mario@mariovavti.com> | 2024-11-09 10:24:26 +0000 |
commit | 0ed08274f16d65b427bd4a5bbd8bd5bd6b2a65c2 (patch) | |
tree | 25b05973f824b95fc5705cf8aa79b86a44cfde00 /Zotlabs | |
parent | 2a152e0803309eb3646316bbe0d2a47353bad2b9 (diff) | |
parent | 0534fe68869aae231259ee48a38b4533f3f1ff99 (diff) | |
download | volse-hubzilla-0ed08274f16d65b427bd4a5bbd8bd5bd6b2a65c2.tar.gz volse-hubzilla-0ed08274f16d65b427bd4a5bbd8bd5bd6b2a65c2.tar.bz2 volse-hubzilla-0ed08274f16d65b427bd4a5bbd8bd5bd6b2a65c2.zip |
Merge branch 'clean-up-some-dependencies' into 'dev'
Clean up deps and upgrade EpubMeta
See merge request hubzilla/core!2162
Diffstat (limited to 'Zotlabs')
-rw-r--r-- | Zotlabs/Thumbs/Epubthumb.php | 47 |
1 files changed, 28 insertions, 19 deletions
diff --git a/Zotlabs/Thumbs/Epubthumb.php b/Zotlabs/Thumbs/Epubthumb.php index 6ebbd8933..b50583e30 100644 --- a/Zotlabs/Thumbs/Epubthumb.php +++ b/Zotlabs/Thumbs/Epubthumb.php @@ -2,31 +2,33 @@ namespace Zotlabs\Thumbs; -require_once 'library/epub-meta/epub.php'; +use SebLucas\EPubMeta\EPub; +use GdImage; /** - * @brief Thumbnail creation for epub files. - * + * Thumbnail creation for epub files. */ class Epubthumb { /** - * @brief Match for application/epub+zip. + * Match for application/epub+zip. * * @param string $type MimeType * @return boolean */ - function Match($type) { - return(($type === 'application/epub+zip') ? true : false ); + function Match(string $type): bool { + return $type === 'application/epub+zip'; } /** - * @brief + * Create the thumbnail if the Epub has a cover. * * @param array $attach * @param number $preview_style unused * @param number $height (optional) default 300 * @param number $width (optional) default 300 + * + * @SuppressWarnings(PHPMD.UnusedFormalParameter) */ function Thumb($attach, $preview_style, $height = 300, $width = 300) { @@ -35,26 +37,33 @@ class Epubthumb { return; } - $photo = false; - - $ep = new \EPub($file); - $data = $ep->Cover(); - - if($data['found']) { - $photo = $data['data']; - } + $image = $this->getCover($file); - if($photo) { - $image = imagecreatefromstring($photo); - $dest = imagecreatetruecolor($width, $height); + if ($image) { $srcwidth = imagesx($image); $srcheight = imagesy($image); + $dest = imagecreatetruecolor($width, $height); imagealphablending($dest, false); imagesavealpha($dest, true); + imagecopyresampled($dest, $image, 0, 0, 0, 0, $width, $height, $srcwidth, $srcheight); + + imagejpeg($dest, "{$file}.thumb"); + imagedestroy($image); - imagejpeg($dest, dbunescbin($attach['content']) . '.thumb'); + imagedestroy($dest); + } + } + + private function getCover(string $filename): GdImage|false { + $epub = new EPub($filename); + $cover = $epub->getCover(); + + if (! empty($cover)) { + return imagecreatefromstring($cover); + } else { + return false; } } } |