Support .svg source images
authorChristian Weiske <cweiske@cweiske.de>
Fri, 26 Nov 2021 10:01:45 +0000 (11:01 +0100)
committerChristian Weiske <cweiske@cweiske.de>
Fri, 26 Nov 2021 10:01:45 +0000 (11:01 +0100)
ChangeLog
README.rst
surrogator.php

index 23984d68f95589d0f4084eafee6ef9b13bd085e1..af2bcc465f9c28deb0e5ffd84421eac7374d68f7 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -2,6 +2,7 @@
 
        * Fix open redirect security issue (CWE-601).
          You have to white-list allowed default URLs now.
+       * Add support for .svg source files
 
 2012-08-27  Christian Weiske  <cweiske@bogo>
 
index 1e6f73c5fedf890a8431f087372369d98ba6486d..6f3575fb5660f6bb5ffc6e23ba427fa6e623b6e6 100644 (file)
@@ -54,7 +54,7 @@ Usage
 1. Put images in ``raw/`` folder.
    Name has to be email address + image file extension, for example
    ``foo@example.org.png``.
-   Surrogator supports ``.png`` and ``.jpg``.
+   Surrogator supports ``.png``, ``.jpg`` and ``svg`` files.
 
    For OpenIDs, use the url-encoded URL + extension as filename, for example
    replace ``/`` with ``%2F``.
@@ -68,6 +68,8 @@ Usage
    when the raw file is newer than the "square" file in the var folder.
    You can force the update with ``--force``.
 
+Note: PHP imagick extension is required for ``svg`` files.
+
 
 ====
 Test
index f418750c28de5027cf571d3b53ae0172da11791c..b397042d1603d24c129ee9adaa94fed8aea2a8de 100755 (executable)
@@ -136,7 +136,7 @@ if (count($files)) {
 } else {
     $fileInfos = new \RegexIterator(
         new \DirectoryIterator($rawDir),
-        '#^.+\.(png|jpg)$#'
+        '#^.+\.(png|jpg|svg|svgz)$#'
     );
 }
 foreach ($fileInfos as $fileInfo) {
@@ -230,8 +230,15 @@ function createSquare($origPath, $ext, $targetPath, $maxSize)
         $imgOrig = imagecreatefrompng($origPath);
     } else if ($ext == 'jpg' || $ext == 'jpeg') {
         $imgOrig = imagecreatefromjpeg($origPath);
+    } else if ($ext == 'svg' || $ext == 'svgz') {
+        $imagickImg = new \Imagick();
+        $imagickImg->setBackgroundColor(new \ImagickPixel('transparent'));
+        $imagickImg->readImage($origPath);
+        $imagickImg->setImageFormat('png32');
+        $imgOrig = imagecreatefromstring($imagickImg->getImageBlob());
     } else {
         //unsupported format
+        logErr('Unsupported image format: ' . $origPath);
         return false;
     }