Display a random image on an external website. Display a random image on an external website.
 

News:

cpg1.5.48 Security release - upgrade mandatory!
The Coppermine development team is releasing a security update for Coppermine in order to counter a recently discovered vulnerability. It is important that all users who run version cpg1.5.46 or older update to this latest version as soon as possible.
[more]

Main Menu

Display a random image on an external website.

Started by djib, January 15, 2006, 01:30:56 PM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

djib

Hello,
How can I display a random image taken from my coppermine gallerie on some other website ?
Thanks.

djib

I found a solution.
<?php 
// ------------------------------------------------------------------------- //
// Coppermine Photo Gallery - random photo displayer                         //
// ------------------------------------------------------------------------- //
// Based on Dr. Tarique Sani RSS feed for Coppermine                         //
// http://tariquesani.net/                                                  //
//
// Adapted by djib to display a random photo - http://djib.biz              //
// This program is free software; you can redistribute it and/or modify     //
// it under the terms of the GNU General Public License as published by     //
// the Free Software Foundation; either version 2 of the License, or        //
// (at your option) any later version.                                      //
// ------------------------------------------------------------------------- //
// Just put into the same directory as your coppermine installation         //
// ------------------------------------------------------------------------ //

define('IN_COPPERMINE'true);
define('INDEX_PHP'true);
require(
'include/init.inc.php');

//How many items you want to show
$thumb_per_page 1;

$thumb_count 4;
$lower_limit 0;


$album 'random';


//Changes these to point to your site if the following is not giving correct results.
$link_url $CONFIG['ecards_more_pic_target']."displayimage.php?pos=-";
$image_url $CONFIG['ecards_more_pic_target']."albums/";


$data get_pic_data($album$thumb_count$album_name$lower_limit$thumb_per_page);


foreach(
$data AS $picture) {

    
$thumb_url "$image_url$picture[filepath]$CONFIG[thumb_pfx]$picture[filename]";
    
$keywords explode(" ",trim($picture[keywords]));
    
$category_string "";
    
$pubDate gmdate("D, d M Y H:i:s"$picture[ctime]);
    
$description '<a href="' $link_url $picture['pid'] . '"><img src="' $thumb_url '"  alt="Random image"/></a>'.bb_decode($picture[caption]).bb_decode($picture[caption_text]);    
    echo 
$description;
}

?>



After that, just add <?php include(http://yoursite/get_photo.php); ?> where you want to display the photo.


Joachim Müller


mqcarpenter

djib that is EXACTLY what I needed. Thank you! And it is super simple, unlike the cpmfetch idea.
One note: you forgot your quotes on the include:

<?php include("http://yoursite/get_photo.php"); ?>
Football is gearing up @ www.returnofthechampions.com

djib

I'm happy you like it mqcarpenter.
Thanks for spotting the error in the include.

Here is a new version of the script that allows to display a chosen number of photos. Photos are now picked up randomly even in one album.

For example get_photo?album=6&nb=4 will display 4 photos from album 6.



<?php 
// ------------------------------------------------------------------------- //
// Coppermine Photo Gallery - RSS Feed                                      //
// ------------------------------------------------------------------------- //
// Copyright (C) Dr. Tarique Sani                                           //
// http://tariquesani.net/                                                  //
// Adapted by djib to display a random photo - http://djib.biz              //
// This program is free software; you can redistribute it and/or modify     //
// it under the terms of the GNU General Public License as published by     //
// the Free Software Foundation; either version 2 of the License, or        //
// (at your option) any later version.                                      //
// ------------------------------------------------------------------------- //
// Just put into the same directory as your coppermine installation         //
// ------------------------------------------------------------------------ //

define('IN_COPPERMINE'true);
define('INDEX_PHP'true);
require(
'include/init.inc.php');

//How many items you want to show in your get_photo script
if(isset($_GET['nb'])) {
     
$thumb_per_page=$_GET['nb'];
} else {
     
$thumb_per_page 4;
}
$thumb_count 4;
$lower_limit 0;

if(isset(
$_GET['album'])){
    
$album $_GET['album'];
}

//If it is a numeric album get the name and set variables
if ((is_numeric($album))){
     
$album_name_keyword get_album_name($album);
     
$CURRENT_CAT_NAME $album_name_keyword['title'];
     
$ALBUM_SET "AND aid IN (".(int)$_GET['album'].")".$ALBUM_SET;
     
//Set the album to last uploaded
     
$album 'random';
}

//If the album is not set set it to lastup - this is the default
if(!isset($album)){
     
$album 'random';
}


//Changes these to point to your site if the following is not giving correct results.
$link_url $CONFIG['ecards_more_pic_target']."displayimage.php?pos=-";
$image_url $CONFIG['ecards_more_pic_target']."albums/";


$data get_pic_data($album$thumb_count$album_name$lower_limit$thumb_per_page);


foreach(
$data AS $picture) {
    
$thumb_url "$image_url$picture[filepath]$CONFIG[thumb_pfx]$picture[filename]";
    
$description '<a href="' $link_url $picture['pid'] . '"><img src="' $thumb_url '"  alt="Photo aléatoire"/></a>';
    echo 
$description;

}
?>


Joachim Müller


IamDeirdre

Deirdre

younk

Is it possible to have it show the normal picture.. not the original but the http://www.babez.dk/galleri/displayimage.php?album=7&pos=1 that picture?

Arnaud

Hello

This code is working on a page but not in my vbulletin template page.

include php () seems not working.. any idea?

thanks

jayanthsharma

djib,
I am immensly happy with your code. I cant believe i struggled for 2 days with cpmfetch to do what this little script does.

Joachim Müller

This script is a nice little contribution, however it has severe drawbacks as far as I can see:
  • Permissions aren't being taken into account
  • Will only work for images, but not for other file types
  • Will only work if in the coppermine root folder

If you can live with those drawbacks, then fine. However, we don't recommend it - we recommend cpmFetch instead.

pcwfreak

This script is nice but how do you get rid of the views and picture name? ???

TuXi

//TuXi

chanfuterboy

ok i see both script

the first one, how to put ( how many views ) under the picture, of my it display aside


The second script.

How to display the picture vertically instead of horrizontly

thanks

truth005

The code is amazing! But is there a way that the blue border around the pic dosnt show up, or a way to customize the border? Also is there a way to show the latest uploaded pictures but have 1 pic show up for each new album like they have on www.shakiramedia.com on there "latest additons"

justbishop

Awesome little script :)  One question...any way to get it to display the latest picutres, rather than randoms?

And the border can be done away with.  Just add border ="0" in this line, toward the very end of the code:
$description = '<a href="' . $link_url . $picture['pid'] . '"><img src="' . $thumb_url . '"  [b]border="0"[/b] alt="Photo aléatoire"/></a>';

I actually crated a class for the picture in my page's css, added the class tag to the above instead of the border one, and can control border color, thickness, etc. from the css now.  note that you can also change the "alt" tag to say something other than "Photo aléatoire."

justbishop

Sorry for the double post.  I didn't see an edit option, and realised only after I posted that bbcode tags don't work within code tags  *headdesk*

so yeah, here's what I really ment to put in the code block above:
$description = '<a href="' . $link_url . $picture['pid'] . '"><img src="' . $thumb_url . '"  border="0" alt="Photo aléatoire"/></

truth005

Quote from: justbishop on May 23, 2006, 09:34:55 PM
Awesome little script :)  One question...any way to get it to display the latest picutres, rather than randoms?

And the border can be done away with.  Just add border ="0" in this line, toward the very end of the code:
$description = '<a href="' . $link_url . $picture['pid'] . '"><img src="' . $thumb_url . '"  [b]border="0"[/b] alt="Photo aléatoire"/></a>';

I actually crated a class for the picture in my page's css, added the class tag to the above instead of the border one, and can control border color, thickness, etc. from the css now.  note that you can also change the "alt" tag to say something other than "Photo aléatoire."

Thanks you! and to have latest pictures change random' to 'lastup'

     $album = 'lastup'; (like this)

justbishop


justbishop

Again, no edit (am I completely missing it?)

Anyway, I have another question...is there a way to use this code to specify a certain category I'd like to display pictures from, rather than an album?  I saw this earlier in the thread:

get_photo?album=6&nb=4

That worked for me in the include, so I figured that changing "album" to "cat" would be worth a shot, but no luck.