Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error converting markup with svgs #34

Open
JonasDoebertin opened this issue Nov 2, 2015 · 15 comments
Open

Error converting markup with svgs #34

JonasDoebertin opened this issue Nov 2, 2015 · 15 comments

Comments

@JonasDoebertin
Copy link

Generally, creating an epub from my html markup works just fine and this library is a HUGE time saver. Thank you so much for creating and maintaining it!

There is only problem I'm facing right now though: Whenever my original HTML markup contains an <img> tag linking to a SVG file, adding it to a chapter fails (with EPub::EXTERNAL_REF_ADD enabled, to embed all image files into the epub file). Adding any other image format like PNGs and JPEGs works as expected and if I disable EPub::EXTERNAL_REF_ADD it works, too. I also tried adding other SVG files which still results in the error.

Here's the exact error message I'm facing:

PHP Warning:  imagecreatefromstring(): Data is not in a recognized format in /Users/path/to/project/vendor/grandt/phpepub/src/PHPePub/Core/EPub.php on line 615

This is the markup related to the SVG I'm trying to convert:

<figure>
    <img src="http://example.com/image.svg" alt="My svg image">
</figure>

Using the latest release with composer.

@Grandt
Copy link
Owner

Grandt commented Nov 2, 2015

Please have a look at 4.0.5-beta1
No guarantees, I only just had time to whip that one up.

@JonasDoebertin
Copy link
Author

You're so fast! Thanks a lot for your efforts!

I'll have a look this evening.

@JonasDoebertin
Copy link
Author

Seems to work beautifully. Thank you so much!

@Grandt
Copy link
Owner

Grandt commented Nov 3, 2015

Can I get you to test one more thing while you are at it?
Try to add a very large SVG (2000x2000 or more) The new code should reduce its size to the confines of the $maxImageWidth/$maxImageHeight settings in EPub.

@JonasDoebertin
Copy link
Author

Hmmm, that doesn't seem to work. Tried adding a 4000x4000 pixels svg file. The svg file included within the .epub is exactly the same as the original file (except that some attributes on the main <svg> element are reordered).

Original svg:

<?xml version="1.0" standalone="no"?><!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN" "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd"><svg width="100%" height="100%" viewBox="0 0 4000 4000" version="1.1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" xml:space="preserve" style="fill-rule:evenodd;clip-rule:evenodd;stroke-linejoin:round;stroke-miterlimit:1.41421;"><g id="Ebene1"><rect x="411.445" y="269.874" width="1021.12" height="1153.57" style="fill:#50df50;"/><ellipse cx="3061.76" cy="1551.06" rx="619.986" ry="1117.49" style="fill:#d2e7e7;"/><path d="M2938.12,1540.04c0,-284.276 -230.796,-515.071 -515.071,-515.071l-1030.14,0c-284.275,0 -515.071,230.795 -515.071,515.071l0,1106.84c0,284.276 230.796,515.071 515.071,515.071l1030.14,0c284.275,0 515.071,-230.795 515.071,-515.071l0,-1106.84Z" style="fill:#ec5656;"/></g></svg>

Svg in epub file:

<?xml version="1.0" standalone="no"?>
<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN" "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd">
<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" width="100%" height="100%" viewBox="0 0 4000 4000" version="1.1" xml:space="preserve" style="fill-rule:evenodd;clip-rule:evenodd;stroke-linejoin:round;stroke-miterlimit:1.41421;"><g id="Ebene1"><rect x="411.445" y="269.874" width="1021.12" height="1153.57" style="fill:#50df50;"/><ellipse cx="3061.76" cy="1551.06" rx="619.986" ry="1117.49" style="fill:#d2e7e7;"/><path d="M2938.12,1540.04c0,-284.276 -230.796,-515.071 -515.071,-515.071l-1030.14,0c-284.275,0 -515.071,230.795 -515.071,515.071l0,1106.84c0,284.276 230.796,515.071 515.071,515.071l1030.14,0c284.275,0 515.071,-230.795 515.071,-515.071l0,-1106.84Z" style="fill:#ec5656;"/></g></svg>

@Grandt
Copy link
Owner

Grandt commented Nov 3, 2015

I think I'll change that and leave the SVG's be. Setting their size changes nothing anyway, unlike the bitmap formats where that'll reduce the size of the files as well.

@JonasDoebertin
Copy link
Author

Seems like your latest commit broke things.

I guess this line (57f3c11#diff-738d6dc186ddd5f8e5366f4bef5652b0R634) shouldn't be commented out, right?

@Grandt
Copy link
Owner

Grandt commented Nov 3, 2015

Agreed, the width and height aren't being set. I'm looking at extracting the SVG metadata now..

@JonasDoebertin
Copy link
Author

Nah, I meant the $image = $xml->asXML(); line which was commented out too by accident, i guess.

@JonasDoebertin
Copy link
Author

I don't think extracting SVG meta data is necessary. It works fine, even with huge SVGs, right now.

@Grandt
Copy link
Owner

Grandt commented Nov 3, 2015

The reason I commented that $image line out was that it should have been irrelevant. $image was already set.

I have committed another one, as I had practically already finished the rescale part. All I'm doing now is reading the hight/width from the viewbox, and place the rescaled size in the width/height attributes.
I builds a valid epub here, though I have to go get a good SVG to test on.
If this build fails on your end, I'll comment out the rescaling segment until I crack it right, or feel confident that it'll work and readers will rescale it themselves.

@JonasDoebertin
Copy link
Author

Seems to work fine with your latest commit. All SVGs get the correct width/height attributes applied and the ePub displays fine for me.

@Grandt
Copy link
Owner

Grandt commented Nov 3, 2015

Thank you for helping me test this. :)

@JonasDoebertin
Copy link
Author

Thank you for maintaining this lib so actively!

@Grandt
Copy link
Owner

Grandt commented Nov 3, 2015

Feel free to let me know if you have any other issues.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants