Smilia: children's dental clinic website (WordPress theme and plugin)
This commit is contained in:
commit
4f4b5f2c0a
266 files changed
+16459
No files matched your search
@@ -0,0 +1,34 @@
|
||||
<?php
|
||||
|
||||
namespace Smilia\Core;
|
||||
|
||||
defined( 'ABSPATH' ) || exit;
|
||||
|
||||
final class Picture {
|
||||
|
||||
private static array $svg_sizes = array();
|
||||
|
||||
public static function svg( string $path, string $url, string $class_name = '', string $alt = '', string $loading = 'lazy' ): void {
|
||||
$size = self::svg_size( $path );
|
||||
$url = is_readable( $path ) ? add_query_arg( 'ver', (string) filemtime( $path ), $url ) : $url;
|
||||
printf(
|
||||
'<img class="%s" src="%s" alt="%s" width="%d" height="%d" decoding="async" loading="%s">',
|
||||
esc_attr( $class_name ),
|
||||
esc_url( $url ),
|
||||
esc_attr( $alt ),
|
||||
(int) $size[0],
|
||||
(int) $size[1],
|
||||
esc_attr( $loading )
|
||||
);
|
||||
}
|
||||
|
||||
private static function svg_size( string $path ): array {
|
||||
if ( ! isset( self::$svg_sizes[ $path ] ) ) {
|
||||
$head = is_readable( $path ) ? (string) file_get_contents( $path, false, null, 0, 600 ) : '';
|
||||
self::$svg_sizes[ $path ] = preg_match( '/viewBox="[\d.\-]+\s+[\d.\-]+\s+([\d.]+)\s+([\d.]+)"/', $head, $m )
|
||||
? array( (int) round( (float) $m[1] ), (int) round( (float) $m[2] ) )
|
||||
: array( 100, 100 );
|
||||
}
|
||||
return self::$svg_sizes[ $path ];
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user