diff options
author | Harald Eilertsen <haraldei@anduin.net> | 2024-11-08 14:41:52 +0100 |
---|---|---|
committer | Harald Eilertsen <haraldei@anduin.net> | 2024-11-08 16:48:23 +0100 |
commit | 0534fe68869aae231259ee48a38b4533f3f1ff99 (patch) | |
tree | 079f392c56da36f5c4fd6b7a011aeab0d037864f /Zotlabs | |
parent | 6e51571309481b64edd40c0571b83bc7a1562b4f (diff) | |
download | volse-hubzilla-0534fe68869aae231259ee48a38b4533f3f1ff99.tar.gz volse-hubzilla-0534fe68869aae231259ee48a38b4533f3f1ff99.tar.bz2 volse-hubzilla-0534fe68869aae231259ee48a38b4533f3f1ff99.zip |
Thumbs\Epubthumb: Adapt to new version of EPub meta lib.
Also fixes a few issues and refactor the code a bit.
Diffstat (limited to 'Zotlabs')
-rw-r--r-- | Zotlabs/Thumbs/Epubthumb.php | 45 |
1 files changed, 27 insertions, 18 deletions
diff --git a/Zotlabs/Thumbs/Epubthumb.php b/Zotlabs/Thumbs/Epubthumb.php index 2eda3a941..b50583e30 100644 --- a/Zotlabs/Thumbs/Epubthumb.php +++ b/Zotlabs/Thumbs/Epubthumb.php @@ -3,30 +3,32 @@ namespace Zotlabs\Thumbs; 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; } } } |