summaryrefslogtreecommitdiff
path: root/src/web/helpers/image.php
diff options
context:
space:
mode:
Diffstat (limited to 'src/web/helpers/image.php')
-rw-r--r--src/web/helpers/image.php94
1 files changed, 0 insertions, 94 deletions
diff --git a/src/web/helpers/image.php b/src/web/helpers/image.php
deleted file mode 100644
index d4683fe..0000000
--- a/src/web/helpers/image.php
+++ /dev/null
@@ -1,94 +0,0 @@
-<?php /* Copyright (c) 2024 Freya Murphy */
-
-function __get_mime($type)
-{
- switch ($type) {
- case 'mp4':
- return 'video/mp4';
- case 'webm':
- return 'video/webm';
- case 'gif':
- return 'image/gif';
- case 'png':
- return 'image/png';
- case 'jpg':
- return 'image/jpeg';
- case 'webp':
- return 'image/webp';
- default:
- return NULL;
- }
-}
-
-function __make_source(
- $name,
- $format,
- $media)
-{
- if ($media) {
- $media = "media=\"$media\"";
- } else {
- $media = '';
- }
- $path = Core::get_url('public/' . $name . '.' . $format, TRUE);
- $mime = __get_mime($format);
- return sprintf('<source type="%s" srcset="%s" %s>',
- $mime, $path, $media);
-}
-
-function image(
- $name,
- $alt,
- $formats = array('webp', 'png'),
- $animated = FALSE,
- $attrs = array(),
-
- $height = NULL,
- $width = NULL,
- $size = NULL) :string
-{
-
- if ($animated === TRUE) {
- $animated = array('gif');
- }
-
- if (!$animated) {
- $animated = array();
- }
-
- $out = "<picture>";
-
- foreach ($formats as $format) {
- $media = count($animated) ? '(prefers-reduced-motion: reduce)' : NULL;
- $out .= __make_source($name, $format, $media);
- }
-
- foreach ($animated as $format) {
- $out .= __make_source($name, $format, NULL);
- }
-
- $format = end($formats);
- $path = Core::get_url('public/' . $name . '.' . $format, TRUE);
- $out .= "<img src=\"$path\"";
- if ($alt) {
- $alt = lang($alt);
- $attrs['alt'] = $alt;
- $attrs['title'] = $alt;
- }
- if ($width) {
- $attrs['width'] = $width;
- }
- if ($height) {
- $attrs['height'] = $height;
- }
- if ($size) {
- $attrs['width'] = $size;
- $attrs['height'] = $size;
- }
- foreach ($attrs as $key => $value) {
- $out .= " $key=\"$value\"";
- }
- $out .= '></picture>';
-
- return $out;
-}