Skip to content

Commit 7445581

Browse files
committed
Expand aspect to include exact width / height matches
Refactor internals to simplify aspect queries.
1 parent f5acf3f commit 7445581

File tree

2 files changed

+12
-7
lines changed

2 files changed

+12
-7
lines changed

README.textile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,7 @@ h4. Attributes (in addition to standard txp:thumbnail tag attributes)
140140
: Adds the image file modification time to the end of the thumbnail's URL. Use @add_stamp="1"@ to switch this feature on. This helps prevent stale images, but may prevent browsers from cacheing the thumbnails properly, thus increasing bandwidth usage.
141141
: Default: @0@.
142142
; @aspect="ratio"@
143-
: Only consider images of a particular aspect ratio. Choose from: @portrait@, @landscape@, or @square@. Or specify your own aspect ratio width:height, e.g. @16:9@ or @4:3@.
143+
: Only consider images of a particular aspect ratio/size. Choose from: @portrait@, @landscape@, or @square@. Or specify your own aspect ratio width:height, e.g. @16:9@ or @4:3@, or numeric ratio such as @aspect="1.33"@ or @aspect="0.8". You may also specify just a width or height, e.g. @aspect="300:"@ (only consider images that are exactly 300px wide) or @aspect=":800"@ (only consider images that are exactly 800px tall).
144144
: Default: unset.
145145
; @break="tag"@
146146
: HTML tag to apply between each thumbnail when iterating over them.

smd_thumbnail.php

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
// 1 = Plugin help is in raw HTML. Not recommended.
1818
# $plugin['allow_html_help'] = 1;
1919

20-
$plugin['version'] = '0.6.0';
20+
$plugin['version'] = '0.6.1';
2121
$plugin['author'] = 'Stef Dawson';
2222
$plugin['author_uri'] = 'https://stefdawson.com/';
2323
$plugin['description'] = 'Multiple image thumbnails of arbitrary dimensions';
@@ -400,7 +400,7 @@ function smd_thumb_create_one()
400400

401401
if ($rs) {
402402
$ret = smd_thumb_make($rs, $curr, 1);
403-
dmp($ret);
403+
404404
if (is_array($ret) && in_array($ret[1], array(E_ERROR, E_NOTICE))) {
405405
$rcode = '415 Unsupported Media Type';
406406
} elseif (!$ret) {
@@ -1779,7 +1779,6 @@ function smd_thumbnail($atts, $thing = null)
17791779
unset($display);
17801780
}
17811781

1782-
$havingClause = '';
17831782
$thing = (empty($form)) ? $thing : fetch_form($form);
17841783

17851784
if ($name) {
@@ -1815,13 +1814,19 @@ function smd_thumbnail($atts, $thing = null)
18151814
$typeClause[] = "width > height";
18161815
} elseif ($aspect === 'square') {
18171816
$typeClause[] = "width = height";
1817+
} elseif (is_numeric($aspect)) {
1818+
$typeClause[] = "ROUND(width/height, 2) = $aspect";
18181819
} elseif (strpos($aspect, ':') !== false) {
18191820
$ratio = explode(':', $aspect);
18201821
$ratiow = $ratio[0];
18211822
$ratioh = !empty($ratio[1]) ? $ratio[1] : '';
18221823

18231824
if (is_numeric($ratiow) && is_numeric($ratioh)) {
1824-
$havingClause = " HAVING ratio = ROUND($ratiow/$ratioh, 2)";
1825+
$typeClause[] = "ROUND(width/height, 2) = " . round($ratiow/$ratioh, 2);
1826+
} elseif (is_numeric($ratiow)) {
1827+
$typeClause[] = "width = $ratiow";
1828+
} elseif (is_numeric($ratioh)) {
1829+
$typeClause[] = "height = $ratioh";
18251830
}
18261831
}
18271832

@@ -1837,7 +1842,7 @@ function smd_thumbnail($atts, $thing = null)
18371842

18381843
if ($rs) {
18391844
extract($rs);
1840-
$thumbs = safe_rows('*, ROUND(width/height, 2) AS ratio', SMD_THUMB, implode(' AND ', $typeClause) . $havingClause . $orderClause);
1845+
$thumbs = safe_rows('*', SMD_THUMB, implode(' AND ', $typeClause) . $orderClause);
18411846
$outset = array();
18421847
$force_size = do_list($force_size);
18431848

@@ -2156,7 +2161,7 @@ function smd_thumbnail_info($atts, $thing = null)
21562161
: Adds the image file modification time to the end of the thumbnail's URL. Use @add_stamp="1"@ to switch this feature on. This helps prevent stale images, but may prevent browsers from cacheing the thumbnails properly, thus increasing bandwidth usage.
21572162
: Default: @0@.
21582163
; @aspect="ratio"@
2159-
: Only consider images of a particular aspect ratio. Choose from: @portrait@, @landscape@, or @square@. Or specify your own aspect ratio width:height, e.g. @16:9@ or @4:3@.
2164+
: Only consider images of a particular aspect ratio/size. Choose from: @portrait@, @landscape@, or @square@. Or specify your own aspect ratio width:height, e.g. @16:9@ or @4:3@, or numeric ratio such as @aspect="1.33"@ or @aspect="0.8". You may also specify just a width or height, e.g. @aspect="300:"@ (only consider images that are exactly 300px wide) or @aspect=":800"@ (only consider images that are exactly 800px tall).
21602165
: Default: unset.
21612166
; @break="tag"@
21622167
: HTML tag to apply between each thumbnail when iterating over them.

0 commit comments

Comments
 (0)