PHP Classes

how to add images?

Recommend this page to a friend!

      EPub  >  All threads  >  how to add images?  >  (Un) Subscribe thread alerts  
Subject:how to add images?
Summary:tried using addFile with image data but image isn't added
Messages:6
Author:Arlo Leach
Date:2011-01-26 21:47:42
Update:2013-01-16 14:51:54
 

  1. how to add images?   Reply   Report abuse  
Picture of Arlo Leach Arlo Leach - 2011-01-26 21:47:42
I'm experimenting with this library and so far it's doing everything I need but one thing. I haven't been able to add an image to my ePub.

I'm using code like this:

$book->addFile("images/cake.jpg", "cake", file_get_contents("recipes/cake.jpg"), "image/jpeg");

In the ePub file that is generated, the "images" directory is created, but there is no cake.jpg file. I traced the addFile in EPub.php to the addFile in Zip.php, and from there I can confirm that my file data exists, but I can't tell what the code is doing after that. Can you help?

  2. Re: how to add images?   Reply   Report abuse  
Picture of Asbjorn Grandt Asbjorn Grandt - 2011-01-26 23:00:15 - In reply to message 1 from Arlo Leach
I can try.

I just tested this with your line exactly as you typed it.
And to be sure, I used the versions of EPub.php and Zip.php on this site.

I do get the images/cake.jpg file added.

For the test the page building the epub were in the same directory as EPub.php, Zip.php and the recipes directory.

Can you please tell me some specifics about your setup. Paths to EPup.php, Zip.php and the recipes directory relative to your calling php script. and which PHP version are you running on?

Best Regards
A.Grandt

  3. Re: how to add images?   Reply   Report abuse  
Picture of Arlo Leach Arlo Leach - 2011-01-26 23:32:19 - In reply to message 2 from Asbjorn Grandt
I'm running PHP 5.3.0 and it sounds like the directory structure you used for your test matches mine.

However, I just discovered my problem. I had been inspecting my ePubs using BBEdit's file browser tool, and it was showing the images directory as being empty. But then I noticed that the ePub file size indicates that the images really are in there. I double-checked my HTML and found that I was putting my images into an images directory within the ePub, but my HTML was looking for them in the root directory.

That's a simple mistake I would have caught earlier, but what I saw -- or didn't see -- in BBEdit sent me in the wrong direction. Thanks for getting me back on track!

  4. Re: how to add images?   Reply   Report abuse  
Picture of Asbjorn Grandt Asbjorn Grandt - 2011-01-26 23:40:54 - In reply to message 3 from Arlo Leach
No problem, Always happy to help :)

Good luck with the project.

Best Regards
A.Grandt

  5. Re: how to add images?   Reply   Report abuse  
Picture of Duc Tran Duc Tran - 2013-01-16 12:36:14 - In reply to message 4 from Asbjorn Grandt
I've added an image
$book->addFile("images/cake.jpg", "cake", file_get_contents("recipes/cake.jpg"), "image/jpeg");
How could I refer to it in my book?

  6. Re: how to add images?   Reply   Report abuse  
Picture of Asbjorn Grandt Asbjorn Grandt - 2013-01-16 14:51:54 - In reply to message 5 from Duc Tran
You have to use a relative url as seen from the page referencing it.
If your html is in text/index.html it can be either
<a href="../images/cake.jpg" />
or
<a href="/images/cake.jpg" />