X-Git-Url: https://jasonwoof.com/gitweb/?a=blobdiff_plain;f=encode.php;h=381e68169539a9c4e13d4e97654947170db20418;hb=f0092052f5357e8e7430a2180a56f1536b613da5;hp=fd282b75af7754ebc62e98f93927f17239791c08;hpb=414082e3e11cee010f869633733eccb4f2161153;p=wfpl.git diff --git a/encode.php b/encode.php index fd282b7..381e681 100644 --- a/encode.php +++ b/encode.php @@ -1,19 +1,9 @@ . +# This program is in the public domain within the United States. Additionally, +# we waive copyright and related rights in the work worldwide through the CC0 +# 1.0 Universal public domain dedication, which can be found at +# http://creativecommons.org/publicdomain/zero/1.0/ # This file contains basic encodings. These are used by the encoder. You can @@ -445,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); }