Textpattern CMS support forum
You are not logged in. Register | Login | Help
- Topics: Active | Unanswered
Re: Invalid SVG?
Bloke wrote #340862:
Interesting. Wonder why my ones failed then. Hmmm…
Your Lexmark file “failed” because the non-zero top & left coordinates in the viewBox (viewBox="79 199 1000 198.3"). Current Textpattern code doesn’t seem to like that. (all the SVG files I actually use in Textpattern context always have zero top & left coordinates.)
Is that requirement for zero top & left coordinates a kind of security or validation check before upload?
Where is that emoji for a solar powered submarine when you need it ?
Sand space – admin theme for Textpattern
phiw13 on Codeberg
Offline
Re: Invalid SVG?
phiw13 wrote #340864:
Your Lexmark file “failed” because the non-zero top & left coordinates in the viewBox (
viewBox="79 199 1000 198.3"). Current Textpattern code doesn’t seem to like that. (all the SVG files I actually use in Textpattern context always have zero top & left coordinates.)Is that requirement for zero top & left coordinates a kind of security or validation check before upload?
I don’t think it does stipulate that. It’s the width and height that must be greater than zero, but – as I wrote above – because the calculation method is wrong, this line calculates the height as 198.3 – 199 = -0.7 and throws it out because the height is negative.
Unless I’ve misunderstood it completely, I think that calculation definitely needs correcting as it’s a bug. I can try – also later in the week – to make a PR for that and the unit conversion.
TXP Builders – finely-crafted code, design and txp
Online
Re: Invalid SVG?
Yeah, I was partly confused by that file, as I hacked it to set the viewBox coordinates to 0 0 and that allowed the file to upload.
There is no limit (in Textpattern code) on the top and left coordinates – afterwards I tested with positive and negative values on (simple) test files and all uploaded correctly.
Where is that emoji for a solar powered submarine when you need it ?
Sand space – admin theme for Textpattern
phiw13 on Codeberg
Offline
Re: Invalid SVG?
Ah, that makes sense. So yes the viewBox calculation looks likely the culprit. Great sleuthing, thank you.
This is all a bit beyond me, but I went through those excellent Josh Comeau articles on SVG and learnt a load, thank you. I never realised how insanely capable and manipulable SVG are. It’s given me some ideas!
The smd plugin menagerie — for when you need one more gribble of power from Textpattern. Bleeding-edge code available on GitHub.
Hire Txp Builders – finely-crafted code, design and Txp
Offline
Re: Invalid SVG?
After an involuntary Covid break (yes, it’s still around), I finally got round to this: PR 2020.
It turns out the unit conversion is already done in the txpsvgtopx() function, but dumping the output from that shows that if no unit is matched, an array is returned which I suppose then fails the subsequent is_numeric test.
Additionally, there’s the viewBox fix mentioned above except I went with (int) rather than (float). The viewBox attribute can contain fractional values, but for the database I assume we want exact pixel values?
All of the svgs in your initial post now upload and the width / height is calculated properly where there is a unit in the svg’s width / height attributes.
TXP Builders – finely-crafted code, design and txp
Online
Re: Invalid SVG?
That’s fab, thank you so much. And simpler than expected.
All merged.
The smd plugin menagerie — for when you need one more gribble of power from Textpattern. Bleeding-edge code available on GitHub.
Hire Txp Builders – finely-crafted code, design and Txp
Offline
Re: Invalid SVG?
Thanks. Yes, it was quicker than I imagined. In case it’s helpful for others, your trick of adding
define('txpdmpfile', 'debug.txt');
to config.php so that any dmp(…) statements added to the code get output to /path/to/your/tmpdir/debug.txt proved invaluable once again.
TXP Builders – finely-crafted code, design and txp
Online