Differences

This shows you the differences between two versions of the page.

english:phpwcms_replacer_rts:frontend_render:random_image [2010/01/04 13:24]
Knut Heermann (flip-flop)
english:phpwcms_replacer_rts:frontend_render:random_image [2018/06/03 18:09] (current)
Line 24: Line 24:
---- ----
-FIXME(besser wäre es aber, die unveränderliche ID zu nehmen...) 
- 
-Hier fehlt noch eine etwas genauere Erklärung.  
-FIXME 
Location: **/template/inc_script/frontend_render/rt_get_random_alias_img_url.php** Location: **/template/inc_script/frontend_render/rt_get_random_alias_img_url.php**
Line 208: Line 204:
   // Hm I want to write some default CSS    // Hm I want to write some default CSS
-   $block['custom_htmlhead']['mycss']  = '  <style type="text/css">' . LF . '  <!--' . LF;+   $block['custom_htmlhead']['mycss']  = '  <style type="text/css" media="screen">' . LF . '  <!--' . LF;
//   $block['custom_htmlhead']['mycss'] .= '   #bg-image'.$content['cat_id'].' { ' . LF; //   $block['custom_htmlhead']['mycss'] .= '   #bg-image'.$content['cat_id'].' { ' . LF;
   $block['custom_htmlhead']['mycss'] .= '   .bg-image { ' . LF;    $block['custom_htmlhead']['mycss'] .= '   .bg-image { ' . LF;
Line 224: Line 220:
Forum: [[http://forum.phpwcms.org/viewtopic.php?f=8&t=14342&p=121758#p121758|{CSS trick: random body background image}]] Forum: [[http://forum.phpwcms.org/viewtopic.php?f=8&t=14342&p=121758#p121758|{CSS trick: random body background image}]]
 +
 +Only images with the name "rand[0-25].jpg" are available (Folder: "images/skins/").
<code html> <code html>
Line 230: Line 228:
<style type="text/css" media="screen"> <style type="text/css" media="screen">
.bg-image { .bg-image {
-   background-image: url(/images/skins/[PHP] echo ("skins".rand(0,25).".jpg")[/PHP]) ;+   background-image: url(images/skins/[PHP] echo ("skins".rand(0,25).".jpg")[/PHP]) ;
} }
</style> </style>
Line 245: Line 243:
$template_default['body']['class'] = 'bg-image id-'; $template_default['body']['class'] = 'bg-image id-';
</code> </code>
 +
 +\\
 +
 +====== Random Images from account folder ======
 +
 +  {RANDOMX:%SRC-LB%:%path%:%WIDTH%x%HEIGHT%}
 +
 +From a specified folder of the accounts  a picture is randomly selected and presented. This extended TAG allows the  specification of the  thumbnails size  and a call of the Lightbox //(SlimBox)//.
 +
 +Like {RANDOM:path}, with the following properties:
 +
 +  * Returns a random image from the specified path
 +  * It looks for image of following type: gif, jpg, jpeg, png.
 +  * **{RANDOMX:path}** will return with %%"path=path/rand_image/"%% --> %%<img src="path/rand_image/..." />%%  
 +  * **{RANDOMX:SRC:path}** will return the absolute %%URI PHPWCMS_URL/path/rand_image/...%%
 +  * **{RANDOMX:SRC-R:path}** will return the relative URI %%path/rand_image/...%%.
 +  * **{RANDOMX:SRC-LB:path:WIDTHxHEIGHT}** willl return a complete html set thumb/LightBox with %%WIDTHxHEIGHT%% for the thumb
 +    * The LightBox presents the images in original size.
 +    * The thumbs are simply scaled down, not stored/recalculated or cropped.
 +
 +\\
 +**Example:** ##%%{RANDOMX:SRC-LB:picture/upload/image/:200x150}%%##
 +
 + 
 +
 +==== PHP: ====
 +
 +**File:** template/inc_Script/forntend_render/rt_randomX_img.php
 +
 +<code php|h rt_randomX_img.php |h>
 +<?php
 +// KH 19.06.11 flip-flop: Random image from normal folder
 +
 +// -------------------------------------------------------------------------------------------
 +// obligate check for phpwcms constants
 +  if (!defined('PHPWCMS_ROOT')) {die("You Cannot Access This Script Directly, Have a Nice Day.");}
 +// -------------------------------------------------------------------------------------------
 +
 +function get_random_image_tagX($path) {
 + // returns an random image from the give path
 + // it looks for image of following type: gif, jpg, jpeg, png
 + // {RANDOMX:path} willl return <img src="path/rand_image" />
 + // {RANDOMX:SRC:path} will return absolute URI PHPWCMS_URL/path/rand_image
 + // {RANDOMX:SRC-R:path} will return only relative path/rand_image
 + // {RANDOMX:SRC-LB:path:%WIDTH%x%HEIGHT%} will return a complete html set for LightBox with WIDTHxHEIGHT for the thumb
 +
 +
 + $imgArray = array();
 + $path = trim($path);
 + $tagX = false; //+KH
 + if(strtoupper(substr($path, 0, 4)) == 'SRC:') {
 + $tag = false;
 + $path = trim(substr($path, 4));
 +
 + // relative path/rand_image
 + } elseif (strtoupper(substr($path, 0, 6)) == 'SRC-R:') { // +KH
 + $tag = false;
 + $tagX = 1;
 + $path = trim(substr($path, 6));
 +
 + // complete html set for LightBox with WIDTHxHEIGHT for the thumb
 + } elseif (strtoupper(substr($path, 0, 7)) == 'SRC-LB:') { // +KH
 + // %WIDTH%x%HEIGHT fallback
 + $width = 150;
 + $height = 100;
 +
 + $tag = false;
 + $tagX = 2;
 + $path = trim(substr($path, 7));
 + $data = explode(':', $path);
 + $path = $data[0];
 +
 + if (isset($data[1])) {  // find WIDTH x HEIGHT
 + $data[1] = preg_replace('/[^0-9x]/', '', $data[1]);
 + $attribute = explode('x', $data[1]);
 + $width = intval($attribute[0]);
 + $height = isset($attribute[1]) ? intval($attribute[1]) : 0;
 + }
 +
 + } else {
 + $tag = true;
 + }
 +
 + $path = trim($path, '/');
 + $imgpath = PHPWCMS_ROOT . '/' . $path . '/';
 + $imageinfo = false;
 +
 + if(is_dir($imgpath)) {
 + $handle = opendir( $imgpath );
 + while($file = readdir( $handle )) {
 +   if( $file{0} != '.' && preg_match('/(\.jpg|\.jpeg|\.gif|\.png)$/i', $file)) {
 + $imgArray[] = $file;
 + }
 + }
 + closedir( $handle );
 + }
 +
 + if(count($imgArray) && ($imageinfo = is_random_image($imgArray, $imgpath))) {
 + if($tag) {  // normal output
 + return '<img src="'.$path.'/'.urlencode($imageinfo['imagename']).'" '.$imageinfo[3].' border="0" alt="'.html_specialchars($imageinfo["imagename"]).'"'.HTML_TAG_CLOSE;
 + } else {
 +
 + if ($tagX === 2) {  // SRC-LB
 + initializeLightbox();
 +// $x = '<img src="'.$path.'/'.urlencode($imageinfo['imagename']).'" '.$imageinfo[3].' border="0" alt="'.html_specialchars($imageinfo["imagename"]).'"'.HTML_TAG_CLOSE;
 +
 + $x  = '<a href="image_resized.php?format=jpg&q=85&imgfile='.$path.'/'.urlencode($imageinfo['imagename']).'" rel="lightbox" target="_blank">';
 + $x .= '<img src="image_resized.php?format=jpg&q=85&imgfile='.$path.'/'.urlencode($imageinfo['imagename']).'" class="image_img" alt="'.html_specialchars($imageinfo["imagename"]).'" height="'.$height.'" width="'.$width.'"></a>';
 + return $x;
 + } elseif (($tagX === 1))  // SRC-R
 + return  $path . '/' . urlencode($imageinfo['imagename']);
 +
 + else
 + return PHPWCMS_URL . $path . '/' . urlencode($imageinfo['imagename']);
 + }
 + }
 +
 + return '';
 +}
 +
 + // randomX Image Tag
 + $search = '/\{RANDOMX:(.*?)\}/e';
 + $replace = 'get_random_image_tagX("$1");';
 +
 + $content["all"] = preg_replace($search, $replace, $content["all"]);
 +// $string = str_replace('&#92;&#039;', '&#039;', $string);
 +// $string = str_replace('&amp;quot;', '&quot;', $string);
 +
 +?>
 +
 +</code>
 +
 +\\
 +
 +
 +===== V1.1 =====
 +
 +FIXME Better translate
 +
 +Identical to the version shown above, but enhanced by the appearance of all images in the specified directory using LightBox //(Next/Prev)//.
 +
 +  * **{RANDOMX:SRC-LBNP:path:WIDTHxHEIGHT}** returns the complete set of html instructions for the LightBox with %%WIDTHxHEIGHT%% for the thumbs and provides all the image files from the specified path in the LightBox.
 +    * The LightBox presents the images in original size.
 +    * The Thumb is simply scaled down, not newly calculated / stored or trimmed //(cropping)//.
 +    * Update 21.06.11:
 +      - The Thumb is reduced proportionally shown according to the size specifications  //(Identical procedure as in the pictures CPs - The largest division ratio is the benchmark for both sides)//.  
 +      - Correction to image type.
 +
 +\\
 +**Example:** ##%%{RANDOMX:SRC-LBNP:picture/upload/image/:200x150}%%##
 +
 +The random thumb is displayed with a maximum size of 200x150px and a link to the LightBox  //(show above "proportionally")//, then all the images from the directory in original size with //(Next/Prev)// can be represented.
 +\\
 +
 +==== PHP V1.1: ====
 +
 +**File:** template/inc_Script/forntend_render/rt_randomX_img.php
 +
 +<code php|h rt_randomX_img.php |h>
 +<?php
 +// KH 21.06.11 flip-flop: Random image from normal folder V1.1
 +
 +// -------------------------------------------------------------------------------------------
 +// obligate check for phpwcms constants
 +  if (!defined('PHPWCMS_ROOT')) {die("You Cannot Access This Script Directly, Have a Nice Day.");}
 +// -------------------------------------------------------------------------------------------
 +
 +
 +function get_random_image_tagX($path) {
 + // returns an random image from the given path
 + // it looks for image of following type: gif, jpg, jpeg, png
 + // {RANDOMX:path} will return <img src="path/rand_image" />
 + // {RANDOMX:SRC:path} will return absolute URI PHPWCMS_URL/path/rand_image
 + // {RANDOMX:SRC-R:path} will return only relative path/rand_image
 + // {RANDOMX:SRC-LB:path:%WIDTH%x%HEIGHT%} will return a complete html set for LightBox with proportional WIDTHxHEIGHT for the thumb
 + // {RANDOMX:SRC-LBNP:path:%WIDTH%x%HEIGHT%} the same like SRC-LB with LightBox Next/Prev pictures from this folder
 +
 +
 + $imgArray = array();
 + $path = trim($path);
 + $tagX = false; //+KH
 + if(strtoupper(substr($path, 0, 4)) == 'SRC:') {
 + $tag = false;
 + $path = trim(substr($path, 4));
 +
 + // relative path/rand_image
 + } elseif (strtoupper(substr($path, 0, 6)) == 'SRC-R:') { // +KH
 + $tag = false;
 + $tagX = 1;
 + $path = trim(substr($path, 6));
 +
 + // complete html set for LightBox with WIDTHxHEIGHT for the thumb
 + } elseif (strtoupper(substr($path, 0, 6)) == 'SRC-LB') { // +KH
 + // %WIDTH%x%HEIGHT fallback
 + $width = 150;
 + $height = 100;
 +
 + $tag = false;
 + $tagX = 2;
 + if (strtoupper(substr($path, 0, 9)) == 'SRC-LBNP:') {
 + $path = trim(substr($path, 9));
 + $tagX = 3;
 + } else
 + $path = trim(substr($path, 7));
 + $data = explode(':', $path);
 + $path = $data[0];
 +
 + if (isset($data[1])) {  // find WIDTH x HEIGHT
 + $data[1] = preg_replace('/[^0-9x]/', '', $data[1]);
 + $attribute = explode('x', $data[1]);
 + $width = intval($attribute[0]);
 + $height = isset($attribute[1]) ? intval($attribute[1]) : 0;
 + }
 +
 + } else {
 + $tag = true;
 + }
 +
 + $path = trim($path, '/');
 + $imgpath = PHPWCMS_ROOT . '/' . $path . '/';
 + $imageinfo = false;
 +
 + if(is_dir($imgpath)) {
 + $handle = opendir( $imgpath );
 + while($file = readdir( $handle )) {
 + if( $file{0} != '.' && preg_match('/(\.jpg|\.jpeg|\.gif|\.png)$/i', $file)) {
 + $imgArray[] = $file;
 + }
 + }
 + closedir( $handle );
 + }
 +
 + // RANDOM
 + if(count($imgArray) && ($imageinfo = is_random_image($imgArray, $imgpath))) {
 + if($tag) {  // normal output
 + return '<img src="'.$path.'/'.urlencode($imageinfo['imagename']).'" '.$imageinfo[3].' border="0" alt="'.html_specialchars($imageinfo["imagename"]).'"'.HTML_TAG_CLOSE;
 + } else {
 +
 + // LightBox output
 + if ($tagX === 2 OR $tagX === 3) {  // SRC-LB OR SRC-LBNP:
 + initializeLightbox();
 +// $x = '<img src="'.$path.'/'.urlencode($imageinfo['imagename']).'" '.$imageinfo[3].' border="0" alt="'.html_specialchars($imageinfo["imagename"]).'"'.HTML_TAG_CLOSE;
 +
 + // Type of image
 + $img_type = substr($imageinfo['mime'], 6); // e.g. image/jpeg -> jpeg
 + if ($imageinfo['2'] == 2) $img_type .= '&q=85'; // Only if jpg = type Nr 2
 +
 + // Proportional image size
 + $img_x = $imageinfo[0] / $width;  // z.B. 800 / 200 = 4,00
 + $img_y = $imageinfo[1] / $height; // z.B. 532 / 100 = 5,32
 +
 + if ($img_x < $img_y) $width = $imageinfo[0] / $img_y;
 + else $height = $imageinfo[1] / $img_x;
 +
 + $x  = '<a href="image_resized.php?format='.$img_type.'&imgfile='.$path.'/'.urlencode($imageinfo['imagename']).'" rel="lightbox[NextPrev]" target="_blank">';
 + $x .= '<img src="image_resized.php?format='.$img_type.'&imgfile='.$path.'/'.urlencode($imageinfo['imagename']).'" class="random-img" alt="'.html_specialchars($imageinfo["imagename"]).'" height="'.$height.'" width="'.$width.'"></a>'.LF;
 + $random_image = $imageinfo['imagename'];
 +
 + // LightBox with Next/Prev: Read all available images in path
 + if ($tagX === 3 ) {  // SRC-LBNP:
 + foreach ($imgArray as $key=>$value) {
 +
 + $imageinfo = @getimagesize($imgpath.$value);  // is it an image?
 +
 + if ($imageinfo) {
 +
 + $img_type = substr($imageinfo['mime'], 6); // e.g. image/jpeg -> jpeg
 + if ($imageinfo['2'] == 2) $img_type .= '&q=85'; // Only if jpg = type Nr 2
 +
 + if ($random_image != $value)  // No double image entry except the random image
 + $x .= '<a href="image_resized.php?format='.$img_type.'&imgfile='.$path.'/'.urlencode($value).'" rel="lightbox[NextPrev]" target="_blank"></a>'.LF;
 + // $x .= '<img src="image_resized.php?format=jpg&q=85&imgfile='.$path.'/'.urlencode($value).'" class="image_img" alt="'.html_specialchars($value).'" height="'.$height.'" width="'.$width.'"></a>'.LF;
 + }
 + }
 +
 + }
 +
 + return $x;
 + } elseif (($tagX === 1))  // SRC-R
 + return  $path . '/' . urlencode($imageinfo['imagename']);
 +
 + else // SRC:
 + return PHPWCMS_URL . $path . '/' . urlencode($imageinfo['imagename']);
 + }
 + }
 +
 + return '';
 +}
 +
 + // randomX Image Tag
 + $search = '/\{RANDOMX:(.*?)\}/e';
 + $replace = 'get_random_image_tagX("$1");';
 +
 + $content["all"] = preg_replace($search, $replace, $content["all"]);
 +// $string = str_replace('&#92;&#039;', '&#039;', $string);
 +// $string = str_replace('&amp;quot;', '&quot;', $string);
 +
 +
 +?>
 +</code>
 +
 +\\
 +
english/phpwcms_replacer_rts/frontend_render/random_image.1262607860.txt.gz · Last modified: 2018/06/03 18:08 (external edit)
www.planmatrix.de www.chimeric.de Creative Commons License Valid CSS Driven by DokuWiki do yourself a favour and use a real browser - get firefox!! Recent changes RSS feed Valid XHTML 1.0