Grandt / PHPePub

PHP Classes for dynamically generating EPub files.
http://www.phpclasses.org/package/6115
241 stars 83 forks source link

Use alt value of img tags when possible while Epub:EXTERNAL_REF_IGNORE is used #12

Closed Trim closed 10 years ago

Trim commented 10 years ago

Hello!

I think, it could be good to display the alt value of images instead of simply removing entire tag.

It can be done with this regexp for example:

$html_content = preg_replace('/<\s*?img.*alt="(.*?)".*?>/', '${1}', $html_content);

I'll use this regular expression in my epub plugin for the Leed RSS reader and I think, it can be usefull for you too.

Thanks for your great work on PHPePub !

Grandt commented 10 years ago

At the point where this happens in EPub, I'm already parsing the HTML DOM, so I'll make the change there.

Thanks for a good idea though :).

I'll be updating GitHub shortly. The addChapter function have a parameter for external references. Previously EPub::EXTERNAL_REF_REPLACE_IMAGES would cause addChapter to replace all images with "[image]", I've changed that if it's present, it'll use the alt tag value instead of "image", else it'll fall back to just "image"

Which version do you use? The regular EPub.php or the new EPub250.php?

Cheers A.Grandt

On 04-10-2013 21:31, Adrien Dorsaz wrote:

Hello!

I think, it could be good to display the alt value of images instead of simply removing entire tag.

It can be done with this regexp for example:

$html_content = pregreplace('/<\s?img.alt="(.?)"._?>/', '${1}', $html_content);

I'll use this regular expression in my epub plugin for the Leed RSS reader and I think, it can be usefull for you too.

Thanks for your great work on PHPePub !

— Reply to this email directly or view it on GitHub https://github.com/Grandt/PHPePub/issues/12.

Trim commented 10 years ago

I'm using Epub250.php simply because I've tried it first and it worked well for my needs (and because I like the modularity).

Indeed, I've used EPub::EXTERNAL_REF_IGNORE because I thought that it was not only about images, but really all external references (like video, audio, ..., but I don't know what a epub can contain).

I think, I'll use the REPLACE_IMAGES so. Thanks !

Grandt commented 10 years ago

You are right, EXTERNAL_REF_IGNORE removes all externals. And it will erase images entirely. I'll have to think about that one for a short while. Should ignore place the image alt value or not...

I'm currently playing with how to best support nested chapters (chapter levels). The EPub.NCX alreasy suppirts it, but I'm still trying to figure out how to expose this in the EPub.

Cheers.

On 05-10-2013 11:51, Adrien Dorsaz wrote:

I'm using Epub250.php simply because I've tried it first and it worked well for my needs (and because I like the modularity).

Indeed, I've used EPub::EXTERNAL_REF_IGNORE because I thought that it was not only about images, but really all external references (like video, audio, ..., but I don't know what a epub can contain).

I think, I'll use the REPLACE_IMAGES so. Thanks !

— Reply to this email directly or view it on GitHub https://github.com/Grandt/PHPePub/issues/12#issuecomment-25745364.

leikxile commented 10 years ago

Hi i'm currently using the Epub.php and i've noticed that when downloading external animated gif images. The images that has been downloaded loses its animation.

Grandt commented 10 years ago

leikxile, even with the latest version updated 2 days ago. I added Gif's as a valid format (older readers using the Adobe Digital Editions, can crash on Gifs.) You need to set $book->isGifImagesEnabled = TRUE; If not, can I get you to send me an example book having this gif to php@grandt.com ?

leikxile commented 10 years ago

Sent

leikxile commented 10 years ago

Updated to the latest version and everything seems to be working now. Thank you!

Grandt commented 10 years ago

Resolved, closing.