protected function createCover($book_contents, $metadata)
{
// Resize Image
if (!empty($metadata['pb_cover_image']) && !\Pressbooks\Image\is_default_cover($metadata['pb_cover_image'])) {
$source_path = \Pressbooks\Utility\get_media_path($metadata['pb_cover_image']);
} else {
$source_path = \Pressbooks\Image\default_cover_path();
}
$dest_image = sanitize_file_name(basename($source_path));
$dest_image = Sanitize\force_ascii($dest_image);
$dest_path = $this->tmpDir . '/OEBPS/assets/' . $dest_image;
$img = wp_get_image_editor($source_path);
if (!is_wp_error($img)) {
// Take the longest dimension of the image and resize.
// Cropping is turned off. The aspect ratio is maintained.
$img->resize(1563, 2500, false);
$img->save($dest_path);
$this->coverImage = $dest_image;
}
// HTML
$html = '<div id="cover-image">';
if ($this->coverImage) {
$html .= sprintf('<img src="assets/%s" alt="%s" />', $this->coverImage, get_bloginfo('name'));
}
$html .= "</div>\n";
// Create file, insert into manifest
$vars = array('post_title' => __('Cover', 'pressbooks'), 'stylesheet' => $this->stylesheet, 'post_content' => $html, 'isbn' => @$metadata['pb_ebook_isbn'], 'lang' => $this->lang);
$file_id = 'front-cover';
$filename = "{$file_id}.{$this->filext}";
file_put_contents($this->tmpDir . "/OEBPS/{$filename}", $this->loadTemplate($this->dir . '/templates/epub201/html.php', $vars));
$this->manifest[$file_id] = array('ID' => -1, 'post_title' => $vars['post_title'], 'filename' => $filename);
}