Forum

Thread tagged as: Question, Problem, Error

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

Márton Lente

Márton Lente 0 points

  • 3 years ago
Ryan Gittings

Ryan Gittings 1 points
Registered Developer

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!

Drew McLellan

Drew McLellan 2638 points
Perch Support

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 line extension=php_fileinfo.dll, which seems to be active (not commented out).

Is there anything else I should check?

Drew McLellan

Drew McLellan 2638 points
Perch Support

It should be listed in your extended diagnostics report.

Let me paste it in here. It seems to me, fileinfo is listed:

Perch information

Perch: 3.0.10
Production mode: Production (100)
Installed apps: content (3.0.10), assets (3.0.10), categories (3.0.10)
DB driver: PDO
DB tables: perch3_categories (0), perch3_category_counts (0), perch3_category_sets (0), perch3_content_index (504), perch3_content_items (113), perch3_content_regions (19), perch3_menu_items (8), perch3_navigation (0), perch3_navigation_pages (0), perch3_page_templates (0), perch3_pages (2), perch3_resource_log (149), perch3_resource_tags (0), perch3_resources (44), perch3_resources_to_tags (0), perch3_settings (20), perch3_user_passwords (0), perch3_user_privileges (27), perch3_user_role_privileges (2), perch3_user_roles (2), perch3_users (1)
Users: 1
App runtimes:

<?php
    $apps_list = [ 
    ];

Editor plug-ins:
H1: 08b40c301d208f8549ecbb4271f0005c
L1: 15df07eb0ec1a7416f1c9efb66523c02
F1: 3b606135b33e6a102526838f4152a807
headerColour: #ffffff
content_singlePageEdit: 1
helpURL:
siteURL: /
hideBranding: 0
content_collapseList: 1
lang: en-gb
installedAt: 3.0.10
update_3.0.10: done
latest_version:
on_sale_version: 3.0.10
headerScheme: light
dashboard: 0
hide_pwd_reset: 0
keyboardShortcuts: 0
content_hideNonEditableRegions: 0
content_frontend_edit: 0
content_skip_region_list: 0
assets_restrict_buckets: 0
logoPath: /perch/resources/3h-logo-1.png
PERCH_DEVELOPMENT: 10
PERCH_STAGING: 50
PERCH_PRODUCTION: 100
PERCH_DB_USERNAME: root
PERCH_DB_SERVER: localhost
PERCH_DB_DATABASE: db_3h
PERCH_DB_PREFIX: perch3_
PERCH_TZ: UTC
PERCH_EMAIL_FROM: contact@martonlente.com
PERCH_EMAIL_FROM_NAME: Márton Lente
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
PERCH_RESPATH: /perch/resources
PERCH_HTML5: 1
PERCH_RUNWAY:
PERCH_ERROR_MODE: DIE
PERCH_DATE_LONG: %d %B %Y
PERCH_DATE_SHORT: %d %b %Y
PERCH_TIME_SHORT: %H:%M
PERCH_TIME_LONG: %H:%M:%S
PERCH_RUNWAY_ROUTED:
PERCH_STRONG_PASSWORDS:
PERCH_ASSET_VERSION: 23f8a1427c17ade109a3
PERCH_DEBUG:
PERCH_PREVIEW_ARG: preview
PERCH_TEMPLATE_PATH: E:\1706_3h-epitesziroda-website\31_Web\perch\templates
PERCH_TEMPLATE_FILTERS:
PERCH_DEFAULT_DOC: index.php
PERCH_DEFAULT_EXT: .php
PERCH_PRODUCTION_MODE: 100
PERCH_XHTML_MARKUP:
PERCH_RWD: 1
PERCH_HTML_ENTITIES:
PERCH_SSL:
PERCH_STRIPSLASHES:
PERCH_PROGRESSIVE_FLUSH: 1
PERCH_PARANOID:
PERCH_FORCE_SECURE_COOKIES:
PERCH_DEFAULT_BUCKET: default
PERCH_TRANSLATION_ASSIST:
PERCH_PASSWORD_MIN_LENGTH: 6
PERCH_MAX_FAILED_LOGINS: 10
PERCH_AUTH_LOCKOUT_DURATION: 1 HOUR
PERCH_VERIFY_UPLOADS:
PERCH_PRIV_ASSIST:
PERCH_CUSTOM_EDITOR_CONFIGS:
PERCH_ENABLE_EXIF: 1
PERCH_AUTH_PLUGIN:
PERCH_DB_CHARSET: utf8
PERCH_DB_PORT:
PERCH_DB_SOCKET:
PERCH_APPS_EDITOR_PLUGIN: markitup
PERCH_APPS_EDITOR_MARKUP_LANGUAGE: markdown

Hosting settings

PHP: 5.6.30
Zend: 2.6.0
OS: WINNT
SAPI: apache2handler
Safe mode: not detected
MySQL client: mysqlnd 5.0.11-dev - 20120503 - $Id: 76b08b24596e12d4553bd41fc93cccd5bac2fe7a $
MySQL server: 5.5.5-10.1.21-MariaDB
Free disk space: 51.55 GB
Extensions: Core, bcmath, calendar, ctype, date, ereg, filter, ftp, hash, iconv, json, mcrypt, SPL, odbc, pcre, Reflection, session, standard, mysqlnd, tokenizer, zip, zlib, libxml, dom, PDO, bz2, SimpleXML, wddx, xml, xmlreader, xmlwriter, apache2handler, openssl, curl, fileinfo, gd, gettext, mbstring, exif, mysql, mysqli, pdo_mysql, pdo_sqlite, Phar, mhash
GD: Yes
ImageMagick: No
PHP max upload size: 4M
PHP max form post size: 16M
PHP memory limit: 256M
Total max uploadable file size: 4M
Resource folder writeable: Yes
Session timeout: 24 minutes
Native JSON: Yes
Filter functions: Yes
Transliteration functions: No
MIBDIRS: D:/xampp/php/extras/mibs
MYSQL_HOME: \xampp\mysql\bin
OPENSSL_CONF: D:/xampp/apache/bin/openssl.cnf
PHP_PEAR_SYSCONF_DIR: \xampp\php
PHPRC: \xampp\php
TMP: \xampp\tmp
HTTP_HOST: 3h.l1
HTTP_USER_AGENT: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:57.0) Gecko/20100101 Firefox/57.0
HTTP_ACCEPT: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8
HTTP_ACCEPT_LANGUAGE: hu-HU,hu;q=0.8,en-US;q=0.5,en;q=0.3
HTTP_ACCEPT_ENCODING: gzip, deflate
HTTP_REFERER: https://3h.l1/perch/core/settings/diagnostics/
HTTP_COOKIE: cmsa=1; PHPSESSID=hnlqu6to47h895ob2v03ok6t95
HTTP_DNT: 1
HTTP_CONNECTION: keep-alive
HTTP_UPGRADE_INSECURE_REQUESTS: 1
PATH: C:\Program Files (x86)\Common Files\Intel\Shared Libraries\redist\intel64\compiler;C:\ProgramData\Oracle\Java\javapath;C:\WINDOWS\system32;C:\WINDOWS;C:\WINDOWS\System32\Wbem;C:\WINDOWS\System32\WindowsPowerShell\v1.0\;C:\Program Files\Common Files\Autodesk Shared\;C:\Program Files (x86)\Autodesk\Backburner\;C:\Program Files (x86)\Extensis\Suitcase Fusion\;C:\Users\martonlente\AppData\Local\Microsoft\WindowsApps;
SystemRoot: C:\WINDOWS
COMSPEC: C:\WINDOWS\system32\cmd.exe
PATHEXT: .COM;.EXE;.BAT;.CMD;.VBS;.VBE;.JS;.JSE;.WSF;.WSH;.MSC
WINDIR: C:\WINDOWS
SERVER_SIGNATURE: <address>Apache/2.4.25 (Win32) OpenSSL/1.0.2j PHP/5.6.30 Server at 3h.l1 Port 80</address>
SERVER_SOFTWARE: Apache/2.4.25 (Win32) OpenSSL/1.0.2j PHP/5.6.30
SERVER_NAME: 3h.l1
SERVER_ADDR: 127.0.0.1
SERVER_PORT: 80
REMOTE_ADDR: 127.0.0.1
DOCUMENT_ROOT: E:/1706_3h-epitesziroda-website/31_Web
REQUEST_SCHEME: http
CONTEXT_DOCUMENT_ROOT: E:/1706_3h-epitesziroda-website/31_Web
SERVER_ADMIN: postmaster@localhost
SCRIPT_FILENAME: E:/1706_3h-epitesziroda-website/31_Web/perch/core/settings/diagnostics/index.php
REMOTE_PORT: 61719
GATEWAY_INTERFACE: CGI/1.1
SERVER_PROTOCOL: HTTP/1.1
REQUEST_METHOD: GET
QUERY_STRING: extended
REQUEST_URI: /perch/core/settings/diagnostics/?extended
SCRIPT_NAME: /perch/core/settings/diagnostics/index.php
PHP_SELF: /perch/core/settings/diagnostics/index.php
REQUEST_TIME_FLOAT: 1507736996.212
REQUEST_TIME: 1507736996

Is there anything else I shall try?

Drew McLellan

Drew McLellan 2638 points
Perch Support

Is this the production server or a dev server?

It's a dev server, I run XAMPP locally on my Windows PC.

Drew McLellan

Drew McLellan 2638 points
Perch Support

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.

Drew McLellan

Drew McLellan 2638 points
Perch Support

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.

Drew McLellan

Drew McLellan 2638 points
Perch Support

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