<?php return function () { if (isset($_GET['id'])) { list($id, $ext) = explode('.', $_GET['id']); $color_bg = $_GET['page']; } else { $parts = explode('/', substr($_SERVER['REQUEST_URI'], strlen('/dynamic/placeholder/'))); list($id, $ext) = explode('.', $parts[0]); $color_bg = $parts[1]; } list($w, $h) = explode('x', $id); $w = (int) $w ?: 100; $h = (int) $h ?: 100; $params['color_bg'] = $color_bg ? preg_replace('[^a-z0-9]', '', $color_bg) : ''; require_once YF_PATH . 'share/functions/yf_placeholder_img.php'; echo yf_placeholder_img($w, $h, $params); return true; // Means success };
/** * Helper to output placeholder image, by default output is data/image */ function placeholder_img($extra = []) { if (!is_array($extra)) { $extra = []; } $w = (int) $extra['width']; $h = (int) $extra['height']; if ($extra['as_url']) { $extra['src'] = url('/dynamic/placeholder/' . $w . 'x' . $h); } else { require_once YF_PATH . 'share/functions/yf_placeholder_img.php'; $img_data = yf_placeholder_img($w, $h, ['no_out' => true] + (array) $extra); $extra['src'] = 'data:image/png;base64,' . base64_encode($img_data); } return '<img' . _attrs($extra, ['src', 'type', 'class', 'id']) . ' />'; }