From 77b156df1823cfd67be72acc2e332f996c35f696 Mon Sep 17 00:00:00 2001 From: Matthieu Leproux Date: Wed, 27 Apr 2022 15:12:40 +0200 Subject: [PATCH] fixes #1657 SVG support (both gallery and admin sides) --- admin/batch_manager_unit.php | 4 ++- admin/include/functions_metadata.php | 30 +++++++++++++++++-- admin/picture_modify.php | 3 +- .../default/template/batch_manager_unit.tpl | 2 +- .../default/template/picture_modify.tpl | 6 +++- include/category_default.inc.php | 2 ++ include/config_default.inc.php | 2 +- include/derivative.inc.php | 13 ++++++-- picture.php | 4 +++ themes/default/template/picture.tpl | 4 +-- themes/default/template/picture_content.tpl | 2 +- themes/default/theme.css | 6 ++++ 12 files changed, 66 insertions(+), 12 deletions(-) diff --git a/admin/batch_manager_unit.php b/admin/batch_manager_unit.php index 7304fbe40..77552f3d3 100644 --- a/admin/batch_manager_unit.php +++ b/admin/batch_manager_unit.php @@ -213,7 +213,8 @@ SELECT { $legend.= ' ('.$row['file'].')'; } - + $extTab = explode('.',$row['path']); + $template->append( 'elements', array_merge($row, array( @@ -228,6 +229,7 @@ SELECT 'DESCRIPTION' => htmlspecialchars(isset($row['comment']) ? $row['comment'] : ""), 'DATE_CREATION' => $row['date_creation'], 'TAGS' => $tag_selection, + 'is_svg' => (strtoupper(end($extTab)) == 'SVG'), ) )); } diff --git a/admin/include/functions_metadata.php b/admin/include/functions_metadata.php index 9092e95fa..22cd279cc 100644 --- a/admin/include/functions_metadata.php +++ b/admin/include/functions_metadata.php @@ -177,12 +177,38 @@ function get_sync_metadata($infos) // for width/height (to compute the multiple size dimensions) $is_tiff = true; } - } $file = original_to_representative($file, $infos['representative_ext']); } + if (in_array(mime_content_type($file), array('image/svg+xml', 'image/svg'))) + { + $xml = file_get_contents($file); + + $xmlget = simplexml_load_string($xml); + $xmlattributes = $xmlget->attributes(); + $width = (int) $xmlattributes->width; + $height = (int) $xmlattributes->height; + $vb = (string) $xmlattributes->viewBox; + + if (isset($width) and $width != "") + { + $infos['width'] = $width; + } elseif (isset($vb)) + { + $infos['width'] = explode(" ", $vb)[2]; + } + + if (isset($height) and $height != "") + { + $infos['height'] = $height; + } elseif (isset($vb)) + { + $infos['height'] = explode(" ", $vb)[3]; + } + } + if ($image_size = @getimagesize($file)) { $infos['width'] = $image_size[0]; @@ -244,7 +270,7 @@ SELECT id, path, representative_ext { continue; } - + // print_r($data); $id = $data['id']; foreach (array('keywords', 'tags') as $key) { diff --git a/admin/picture_modify.php b/admin/picture_modify.php index b9dd9df97..f160b23c5 100644 --- a/admin/picture_modify.php +++ b/admin/picture_modify.php @@ -295,7 +295,8 @@ $intro_vars = array( 'size' => l10n('%s pixels, %.2f MB', $row['width'].'×'.$row['height'], $row['filesize']/1024), 'stats' => l10n('Visited %d times', $row['hit']), 'id' => l10n($row['id']), - 'ext' => l10n('%s file type',strtoupper(end($extTab))) + 'ext' => l10n('%s file type',strtoupper(end($extTab))), + 'is_svg'=> (strtoupper(end($extTab)) == 'SVG'), ); if ($conf['rate'] and !empty($row['rating_score'])) diff --git a/admin/themes/default/template/batch_manager_unit.tpl b/admin/themes/default/template/batch_manager_unit.tpl index 61a94d49a..f770f8120 100644 --- a/admin/themes/default/template/batch_manager_unit.tpl +++ b/admin/themes/default/template/batch_manager_unit.tpl @@ -56,7 +56,7 @@ jQuery("a.preview-box").colorbox( { {$element.LEGEND} - + {'Edit'|@translate} diff --git a/admin/themes/default/template/picture_modify.tpl b/admin/themes/default/template/picture_modify.tpl index 1245890fd..9bfff1a83 100644 --- a/admin/themes/default/template/picture_modify.tpl +++ b/admin/themes/default/template/picture_modify.tpl @@ -96,7 +96,7 @@ $('#action-delete-picture').on('click', function() { {combine_css path="admin/themes/default/fontello/css/animation.css" order=10} {* order 10 is required, see issue 1080 *}
-
+
{if isset($U_JUMPTO)} @@ -110,7 +110,11 @@ $('#action-delete-picture').on('click', function() { {/if}
+ {if $INTRO.is_svg} + {'Thumbnail'|translate} + {else} {'Thumbnail'|translate} + {/if}
diff --git a/include/category_default.inc.php b/include/category_default.inc.php index 0cf5a5573..fb37ddb1e 100644 --- a/include/category_default.inc.php +++ b/include/category_default.inc.php @@ -104,6 +104,8 @@ foreach ($pictures as $row) 'URL' => $url, 'DESCRIPTION' => $desc, 'src_image' => new SrcImage($row), + 'path_ext' => strtolower(get_extension($row['path'])), + 'file_ext' => strtolower(get_extension($row['file'])), ) ); if ($conf['index_new_icon']) diff --git a/include/config_default.inc.php b/include/config_default.inc.php index b818d7d67..1df9a7716 100644 --- a/include/config_default.inc.php +++ b/include/config_default.inc.php @@ -45,7 +45,7 @@ $conf['picture_ext'] = array('jpg','jpeg','png','gif'); // file_ext : file extensions (case sensitive) authorized $conf['file_ext'] = array_merge( $conf['picture_ext'], - array('tiff', 'tif', 'mpg','zip','avi','mp3','ogg','pdf') + array('tiff', 'tif', 'mpg','zip','avi','mp3','ogg','pdf','svg') ); // enable_formats: should Piwigo search for multiple formats? diff --git a/include/derivative.inc.php b/include/derivative.inc.php index fab4a8e28..cf8293334 100644 --- a/include/derivative.inc.php +++ b/include/derivative.inc.php @@ -42,6 +42,8 @@ final class SrcImage $this->id = $infos['id']; $ext = strtolower(get_extension($infos['path'])); + $infos['file_ext'] = @strtolower(get_extension($infos['file'])); + $infos['path_ext'] = $ext; if (in_array($ext, $conf['picture_ext'])) { $this->rel_path = $infos['path']; @@ -57,10 +59,17 @@ final class SrcImage $this->flags |= self::IS_MIMETYPE; if ( ($size=@getimagesize(PHPWG_ROOT_PATH.$this->rel_path)) === false) { - $this->rel_path = 'themes/default/icon/mimetypes/unknown.png'; + if ('svg' == $ext) + { + $this->rel_path = $infos['path']; + } + else + { + $this->rel_path = 'themes/default/icon/mimetypes/unknown.png'; + } $size = getimagesize(PHPWG_ROOT_PATH.$this->rel_path); } - $this->size = array($size[0],$size[1]); + $this->size = @array($size[0],$size[1]); } if (!$this->size) diff --git a/picture.php b/picture.php index 7cebc101d..d7adab8c4 100644 --- a/picture.php +++ b/picture.php @@ -507,6 +507,10 @@ while ($row = pwg_db_fetch_assoc($result)) $row['src_image'] = new SrcImage($row); $row['derivatives'] = DerivativeImage::get_all($row['src_image']); + $extTab = explode('.',$row['path']); + $row['path_ext'] = strtolower(get_extension($row['path'])); + $row['file_ext'] = strtolower(get_extension($row['file'])); + if ($i=='current') { $row['element_path'] = get_element_path($row); diff --git a/themes/default/template/picture.tpl b/themes/default/template/picture.tpl index d3f3127fb..90f63039b 100644 --- a/themes/default/template/picture.tpl +++ b/themes/default/template/picture.tpl @@ -149,7 +149,7 @@ y.callService( {if isset($previous)} {elseif isset($U_UP)} {elseif isset($U_UP)}