Textpattern CMS support forum
You are not logged in. Register | Login | Help
- Topics: Active | Unanswered
 
[plugin] [ORPHAN] dca_random_image: Random Image from a Directory
This will output a random image, selected from gif, png, or jpg files stored in a directory at the top level of your site. The default name for the directory is random.
- download dca_random_image.gz
 - unzip and put the .txt file somewhere handy on your computer
 - make sure 
use_pluginsis set to 1 in /lib/admin-config.php - go to admin -> plugins and use the form at the top to select the .txt file to install
 - put 
<txp:dca_random_image />on a template to try it out 
text*
Offline
Re: [plugin] [ORPHAN] dca_random_image: Random Image from a Directory
Dean, there is bug in this plugin.
You have an array('gif','jpg','png'), but since array items are numbered starting with 0, the evaluation of isset($types[$type]) fails for PNG. The $type here needs to be decremented by one.
Last edited by mamash (2004-04-14 18:30:10)
Who’s gonna textdrive you home tonight?
Offline
Re: [plugin] [ORPHAN] dca_random_image: Random Image from a Directory
OK, I like this plugin because it allows me to simply use a symlinked dir from another Photostack site.
A little suggestion. If you extend the last condition before adding the file into the array by
&& array_search(substr(strrchr($file,"."),1),$types) !== false
it will only process files which have the right extension. This way, other files like HTML etc. get excluded straight away, avoiding a ‘not an image’ situation.
Who’s gonna textdrive you home tonight?
Offline
Re: [plugin] [ORPHAN] dca_random_image: Random Image from a Directory
Good call.
text*
Offline
#5 2004-04-16 13:21:22
- lllama
 - New Member
 
- Registered: 2004-03-30
 - Posts: 3
 
Re: [plugin] [ORPHAN] dca_random_image: Random Image from a Directory
Some image editing packages will save an icon file that starts with a ‘.’; Graphic Convertor under OS X for example. When this happens the icon files get read along with the actual image but fail to display. The array_search added by mamash may actually solve this as a happy by-product though.
Offline
Re: [plugin] [ORPHAN] dca_random_image: Random Image from a Directory
The array_search will only check if the file has a proper image extension. You might want to do another check on the first character. Or maybe having a single regex pattern would be more elegant.
Who’s gonna textdrive you home tonight?
Offline
#7 2004-04-16 22:45:10
- lllama
 - New Member
 
- Registered: 2004-03-30
 - Posts: 3
 
Re: [plugin] [ORPHAN] dca_random_image: Random Image from a Directory
True. I didn’t spot the extra ‘r’ in strrchr. My bad.
Offline
Re: [plugin] [ORPHAN] dca_random_image: Random Image from a Directory
If you have the GD library installed, you can do this:
<pre>
$imageinfo = getimagesize(‘/path/to/image.jpg’);
if($imageinfo[ 0] > $imageinfo[ 1])
  {
  /* Width is greater than height */
  }
else
  {
  /* Height is greater than width */
  }</pre>
Last edited by Sketch (2004-06-05 14:34:11)
Aaron Brazell
United States Navy
chmod a+x /bin/laden – Give everyone permission to execute /bin/laden
Offline
Re: [plugin] [ORPHAN] dca_random_image: Random Image from a Directory
can you use this to put out a background image in a style sheet?
Offline
Re: [plugin] [ORPHAN] dca_random_image: Random Image from a Directory
http://www.alistapart.com/articles/randomizer/
Offline
#11 2004-06-06 01:06:26
- Boogenstein
 - Member
 
- From: Wausau, Wisconsin, USA.
 - Registered: 2004-03-28
 - Posts: 56
 
Re: [plugin] [ORPHAN] dca_random_image: Random Image from a Directory
The method that erwin links to can be used for background images in a style sheet. It can even be easily modified to serve up random text.
“Keep a straight face and you’ll be laughing!”
Offline