From 5729ccb32f359a8d99a8209330f0b9bfc6dabc2b Mon Sep 17 00:00:00 2001 From: Christian Weiske Date: Fri, 26 Nov 2021 11:01:45 +0100 Subject: [PATCH] Support .svg source images --- ChangeLog | 1 + README.rst | 4 +++- surrogator.php | 9 ++++++++- 3 files changed, 12 insertions(+), 2 deletions(-) diff --git a/ChangeLog b/ChangeLog index 23984d6..af2bcc4 100644 --- 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 diff --git a/README.rst b/README.rst index 1e6f73c..6f3575f 100644 --- a/README.rst +++ b/README.rst @@ -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 diff --git a/surrogator.php b/surrogator.php index f418750..b397042 100755 --- a/surrogator.php +++ b/surrogator.php @@ -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; } -- 2.30.2