Go to main content

Textpattern CMS support forum

You are not logged in. Register | Login | Help

#1 2004-04-04 13:19:01

Dean
Founder (Gone, but not forgotten)
From: Languedoc
Registered: 2004-02-14
Posts: 235
Website

[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_plugins is 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

#2 2004-04-14 18:29:30

mamash
Member
From: Prague
Registered: 2004-02-21
Posts: 127
Website

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

#3 2004-04-14 21:59:32

mamash
Member
From: Prague
Registered: 2004-02-21
Posts: 127
Website

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

#4 2004-04-15 07:13:12

Dean
Founder (Gone, but not forgotten)
From: Languedoc
Registered: 2004-02-14
Posts: 235
Website

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

#6 2004-04-16 18:44:37

mamash
Member
From: Prague
Registered: 2004-02-21
Posts: 127
Website

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

#8 2004-06-05 14:32:29

Sketch
Archived Plugin Author
From: Washington, D.C.
Registered: 2004-05-20
Posts: 23
Website

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

#9 2004-06-05 22:01:17

bleveck
Member
Registered: 2004-05-30
Posts: 52
Website

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

#10 2004-06-05 22:28:12

erwin
New Member
Registered: 2004-05-19
Posts: 7
Website

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

Board footer

Powered by FluxBB