mirror of
https://github.com/getgrav/grav.git
synced 2026-02-21 14:08:02 +01:00
Add Vector image auto_sizes support
This commit is contained in:
committed by
Matias Griese
parent
2c252c43b4
commit
c4e10cf59f
@@ -159,8 +159,9 @@ class MediumFactory
|
||||
return new ImageMedium($items, $blueprint);
|
||||
case 'thumbnail':
|
||||
return new ThumbnailImageMedium($items, $blueprint);
|
||||
case 'animated':
|
||||
case 'vector':
|
||||
return new VectorImageMedium($items, $blueprint);
|
||||
case 'animated':
|
||||
return new StaticImageMedium($items, $blueprint);
|
||||
case 'video':
|
||||
return new VideoMedium($items, $blueprint);
|
||||
|
||||
63
system/src/Grav/Common/Page/Medium/VectorImageMedium.php
Normal file
63
system/src/Grav/Common/Page/Medium/VectorImageMedium.php
Normal file
@@ -0,0 +1,63 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @package Grav\Common\Page
|
||||
*
|
||||
* @copyright Copyright (c) 2015 - 2022 Trilby Media, LLC. All rights reserved.
|
||||
* @license MIT License; see LICENSE file for details.
|
||||
*/
|
||||
|
||||
namespace Grav\Common\Page\Medium;
|
||||
|
||||
use Grav\Common\Data\Blueprint;
|
||||
|
||||
|
||||
/**
|
||||
* Class StaticImageMedium
|
||||
* @package Grav\Common\Page\Medium
|
||||
*/
|
||||
class VectorImageMedium extends StaticImageMedium
|
||||
{
|
||||
/**
|
||||
* Construct.
|
||||
*
|
||||
* @param array $items
|
||||
* @param Blueprint|null $blueprint
|
||||
*/
|
||||
public function __construct($items = [], Blueprint $blueprint = null)
|
||||
{
|
||||
parent::__construct($items, $blueprint);
|
||||
|
||||
$height = false;
|
||||
$width = false;
|
||||
|
||||
if (!extension_loaded('simplexml')) {
|
||||
return;
|
||||
}
|
||||
|
||||
$path = $this->get('filepath');
|
||||
if (!$path || !file_exists($path) || !filesize($path)) {
|
||||
return;
|
||||
}
|
||||
|
||||
$xml = simplexml_load_string(file_get_contents($path));
|
||||
$attr = $xml->attributes();
|
||||
|
||||
if (!$attr instanceof \SimpleXMLElement) {
|
||||
return;
|
||||
}
|
||||
|
||||
if ($attr->width > 0 && $attr->height > 0) {
|
||||
$width = (int)$attr->width;
|
||||
$height = (int)$attr->height;
|
||||
} elseif ($attr->viewBox && count($size = explode(' ', $attr->viewBox)) === 4) {
|
||||
$width = (int)$size[2];
|
||||
$height = (int)$size[3];
|
||||
}
|
||||
|
||||
if ($width && $height) {
|
||||
$this->def('width', $width);
|
||||
$this->def('height', $height);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user