Forum
SVG error on save
Hello,
I have a similar issue that was already posted on the forum some days ago – though as I see no solution has been made – so I share it again.
When I upload an SVG file, it seems to be working on the site itself, but throws the warning below in the admin:
Warning: Division by zero in E:\1706_3h-epitesziroda-website\31_Web\perch\core\lib\PerchImage.class.php on line 107
Warning: Division by zero in E:\1706_3h-epitesziroda-website\31_Web\perch\core\lib\PerchImage.class.php on line 114
The SVGs I'm trying to upload doesn't have height and width properties embedded, but are stylized by CSS. As they're the 'raw' files from the 'Icon54' icon set, I don't want to manually add height and witdth properties to about 5.000 of them (as well as I want the client to be able to upload their own). Is there a good Perch workaround for this – so that I can use these SVGs as they are?
Here is an SVG file sample, with that I have this error (other icons from the referenced icon set have a similar structure):
<?xml version="1.0" encoding="utf-8"?>
<!-- Generator: Adobe Illustrator 19.0.0, SVG Export Plug-In . SVG Version: 6.00 Build 0) -->
<svg version="1.1" id="Layer_1" xmlns="https://www.w3.org/2000/svg" xmlns:xlink="https://www.w3.org/1999/xlink" x="0px" y="0px"
viewBox="0 0 30 30" style="enable-background:new 0 0 30 30;" xml:space="preserve">
<g>
<g>
<path d="M15,29.5C7,29.5,0.5,23,0.5,15S7,0.5,15,0.5S29.5,7,29.5,15S23,29.5,15,29.5z M15,1.5C7.6,1.5,1.5,7.6,1.5,15
S7.6,28.5,15,28.5S28.5,22.4,28.5,15S22.4,1.5,15,1.5z"/>
</g>
<g>
<path d="M22,15.5h-7c-0.3,0-0.5-0.2-0.5-0.5V5c0-0.3,0.2-0.5,0.5-0.5s0.5,0.2,0.5,0.5v9.5H22c0.3,0,0.5,0.2,0.5,0.5
S22.3,15.5,22,15.5z"/>
</g>
</g>
</svg>
I'm on Windows – I don't know if it matters.
Here is my diagnostic information, just in case:
Perch: 3.0.10, PHP: 5.6.30, MySQL: mysqlnd 5.0.11-dev - 20120503 - $Id: 76b08b24596e12d4553bd41fc93cccd5bac2fe7a $, with PDO
Server OS: WINNT, apache2handler
Installed apps: content (3.0.10), assets (3.0.10), categories (3.0.10)
App runtimes: <?php $apps_list = [ ];
PERCH_LOGINPATH: /perch
PERCH_PATH: E:\1706_3h-epitesziroda-website\31_Web\perch
PERCH_CORE: E:\1706_3h-epitesziroda-website\31_Web\perch\core
PERCH_RESFILEPATH: E:\1706_3h-epitesziroda-website\31_Web\perch\resources
Image manipulation: GD
PHP limits: Max upload 4M, Max POST 16M, Memory: 256M, Total max file upload: 4M
F1: 3b606135b33e6a102526838f4152a807
Resource folder writeable: Yes
HTTP_HOST: 3h.l1
DOCUMENT_ROOT: E:/1706_3h-epitesziroda-website/31_Web
REQUEST_URI: /perch/core/settings/diagnostics/
SCRIPT_NAME: /perch/core/settings/diagnostics/index.php
Thank you in advance, Márton Lente
I think SVGs should have width/height attributes, so that's why the error is being shown. If the CSS stylesheet didn't load for some reason, you're left with an SVG with no sizing specification.
A workaround for your issue could be to do a find and replace for the viewBox element, and add width and height that way. Hope that helps!
I believe the issue comes from the server not being able to detect the file type. Seems to be unique to Windows servers.
Do you have
finfo
installed?Dear Ryan and Drew,
Thank you for your answer. Adding width and height values solves the problem, but it isn't always perfect, as clients may download SVGs from internet, and want to use them as they are with no technical background.
I'm using XAMPP on Windows, and it seems
finfo
is installed, though I'm not sure if I'm checking this at the right place.Basically there is a XAMPP
php.ini
settings file, in that there is a lineextension=php_fileinfo.dll
, which seems to be active (not commented out).Is there anything else I should check?
It should be listed in your extended diagnostics report.
Let me paste it in here. It seems to me,
fileinfo
is listed:Is there anything else I shall try?
Is this the production server or a dev server?
It's a dev server, I run XAMPP locally on my Windows PC.
Can you test to see if it's an issue in production?
Sure, I'll let you know here within 10 minutes.
The answer is yes, I get exactly the same error on the production server. No difference unfortunately.
Is the production server also Windows?
No, the server runs on Linux. So that running the Perch website on Windows or Linux based server doesn't seem to make a difference regarding the above.
That's curious. In which case, I don't have an immediate solution for you. I'll have to look into it for a future update.
No problem, thank you for following my 'experiments'!
I'll go with the 'manual' solution then, adding width and height to SVGs that Ryan suggested above. It solves another additional issue I've just spotted, that you can't see previews for SVG files without width and height properties in the admin, as Perch tries to display them with 0px width and height. Maybe it's worth considering in an upcoming update too.
Have a nice day, Márton Lente