From f8a8d44598bdb6e4446920b8d10d1bc62916c9aa Mon Sep 17 00:00:00 2001 From: Jason Woofenden Date: Fri, 6 Nov 2015 16:25:14 -0500 Subject: [PATCH] add enc_* to get resized cms_image urls --- encode.php | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/encode.php b/encode.php index 43a8a2d..381e681 100644 --- a/encode.php +++ b/encode.php @@ -435,8 +435,31 @@ function wfpl_nth_word($str, $n) { # encoding is a space separated list of: # image_filename width height thumb_filename thumb_width thumb_height function enc_image_src($str) { return wfpl_nth_word($str, 0); } +function _enc_image_src_at_width($str, $width) { + $src = enc_image_src($str); + if ($src) { + return + substr($src, 0, -4) + . 'w' + . $width + . substr($src, -4); + } + return ''; +} +# define these width constants in your config.php +function enc_image_src_full($str) { return _enc_image_src_at_width($str, WFPL_IMAGE_WIDTH_FULL); } +function enc_image_src_small($str) { return _enc_image_src_at_width($str, WFPL_IMAGE_WIDTH_SMALL); } +function enc_image_src_thumb($str) { return _enc_image_src_at_width($str, WFPL_IMAGE_WIDTH_THUMB); } function enc_image_width($str) { return wfpl_nth_word($str, 1); } function enc_image_height($str) { return wfpl_nth_word($str, 2); } +function enc_image_aspect($str) { + $a = explode(' ', $str); + if (count($a) < 3) { + return ''; + } + return ''.(round(100000 * ((int)$a[2]) / ((int)$a[1]) / 1000)).'%'; +} +# obsolete: function enc_thumb_src($str) { return wfpl_nth_word($str, 3); } function enc_thumb_width($str) { return wfpl_nth_word($str, 4); } function enc_thumb_height($str) { return wfpl_nth_word($str, 5); } -- 1.7.10.4