getCover($file); 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); 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; } } }