appendImage() public method

Append an image.
public appendImage ( resource $img )
$img resource An image file (for example, created by `imagecreate`)
Example #1
0
 /**
  * Use PHPMobi to dump a .mobi file.
  *
  * @return Response
  */
 private function produceMobi()
 {
     $mobi = new \MOBI();
     $content = new \MOBIFile();
     /*
      * Book metadata
      */
     $content->set('title', $this->title);
     $content->set('author', implode($this->authors));
     $content->set('subject', $this->title);
     /*
      * Front page
      */
     $content->appendParagraph($this->getExportInformation('PHPMobi'));
     if (file_exists($this->logoPath)) {
         $content->appendImage(imagecreatefrompng($this->logoPath));
     }
     $content->appendPageBreak();
     /*
      * Adding actual entries
      */
     foreach ($this->entries as $entry) {
         $content->appendChapterTitle($entry->getTitle());
         $content->appendParagraph($entry->getContent());
         $content->appendPageBreak();
     }
     $mobi->setContentProvider($content);
     // the browser inside Kindle Devices doesn't likes special caracters either, we limit to A-z/0-9
     $this->title = preg_replace('/[^A-Za-z0-9\\-]/', '', $this->title);
     return Response::create($mobi->toString(), 200, ['Accept-Ranges' => 'bytes', 'Content-Description' => 'File Transfer', 'Content-type' => 'application/x-mobipocket-ebook', 'Content-Disposition' => 'attachment; filename="' . $this->title . '.mobi"', 'Content-Transfer-Encoding' => 'binary']);
 }
Example #2
0
 $mobi = new MOBI();
 $content = new MOBIFile();
 $content->set('title', 'My first eBook');
 $content->set('author', 'Me');
 $content->appendChapterTitle('Introduction');
 for ($i = 0, $lenI = rand(5, 10); $i < $lenI; ++$i) {
     $content->appendParagraph('P' . ($i + 1));
 }
 //Based on PHP's imagecreatetruecolor help paage
 $im = imagecreatetruecolor(220, 200);
 $text_color = imagecolorallocate($im, 233, 14, 91);
 imagestring($im, 10, 5, 5, 'A Simple Text String', $text_color);
 imagestring($im, 5, 15, 75, 'A Simple Text String', $text_color);
 imagestring($im, 3, 25, 125, 'A Simple Text String', $text_color);
 imagestring($im, 2, 10, 155, 'A Simple Text String', $text_color);
 $content->appendImage($im);
 imagedestroy($im);
 $content->appendPageBreak();
 for ($i = 0, $lenI = rand(10, 15); $i < $lenI; ++$i) {
     $content->appendChapterTitle($i + 1 . '. Chapter ' . ($i + 1));
     for ($j = 0, $lenJ = rand(20, 40); $j < $lenJ; ++$j) {
         $content->appendParagraph('P' . ($i + 1) . '.' . ($j + 1) . ' TEXT TEXT TEXT');
     }
     $content->appendPageBreak();
 }
 $mobi->setContentProvider($content);
 //Get title and make it a 12 character long filename
 $title = $mobi->getTitle();
 if ($title === false) {
     $title = 'file';
 }
 /**
  * MOBI Class
  * @author Sander Kromwijk
  */
 public function produceMobi()
 {
     try {
         Tools::logm('Starting to produce Mobi file');
         $mobi = new MOBI();
         $content = new MOBIFile();
         $messages = new Messages();
         // for later
         Tools::logm('Filling metadata for Mobi...');
         $content->set("title", $this->bookTitle);
         $content->set("author", $this->author);
         $content->set("subject", $this->bookTitle);
         # introduction
         $content->appendParagraph('<div style="text-align:center;" ><p>' . _('Produced by wallabag with PHPMobi') . '</p><p>' . _('Please open <a href="https://github.com/wallabag/wallabag/issues" >an issue</a> if you have trouble with the display of this E-Book on your device.') . '</p></div>');
         $content->appendImage(imagecreatefrompng("themes/_global/img/appicon/apple-touch-icon-152.png"));
         $content->appendPageBreak();
         Tools::logm('Adding actual content...');
         foreach ($this->entries as $item) {
             $content->appendChapterTitle($item['title']);
             $content->appendParagraph($item['content']);
             $content->appendPageBreak();
         }
         $mobi->setContentProvider($content);
         // the browser inside Kindle Devices doesn't likes special caracters either, we limit to A-z/0-9
         $this->bookFileName = preg_replace('/[^A-Za-z0-9\\-]/', '', $this->bookFileName);
         // we offer file to download
         $mobi->download($this->bookFileName . '.mobi');
         Tools::logm('Mobi file produced');
     } catch (Exception $e) {
         Tools::logm('PHPMobi has encountered an error : ' . $e->getMessage());
         $this->wallabag->messages->add('e', $e->getMessage());
     }
 }