Advanced search  

News:

CPG Release 1.6.26
Correct PHP8.2 issues with user and language managers.
Additional fixes for PHP 8.2
Correct PHP8 error with SMF 2.0 bridge.
Correct IPTC supplimental category parsing.
Download and info HERE

Pages: [1] 2 3 4   Go Down

Author Topic: Display a random image on an external website.  (Read 92400 times)

0 Members and 1 Guest are viewing this topic.

djib

  • Coppermine newbie
  • Offline Offline
  • Posts: 4
Display a random image on an external website.
« on: January 15, 2006, 01:30:56 pm »

Hello,
How can I display a random image taken from my coppermine gallerie on some other website ?
Thanks.
« Last Edit: March 11, 2006, 09:46:38 pm by GauGau »
Logged

djib

  • Coppermine newbie
  • Offline Offline
  • Posts: 4
Re: Display a random image on an external website.
« Reply #1 on: January 15, 2006, 04:03:39 pm »

I found a solution.
Code: [Select]
<?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.

Logged

Joachim Müller

  • Dev Team member
  • Coppermine addict
  • ****
  • Offline Offline
  • Gender: Male
  • Posts: 47843
  • aka "GauGau"
    • gaugau.de
Logged

mqcarpenter

  • Coppermine newbie
  • Offline Offline
  • Posts: 14
    • OTB Design
Re: Display a random image on an external website.
« Reply #3 on: February 25, 2006, 05:23:59 pm »

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:

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

djib

  • Coppermine newbie
  • Offline Offline
  • Posts: 4
Re: Display a random image on an external website.
« Reply #4 on: March 11, 2006, 07:07:18 pm »

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.


Code: [Select]
<?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;

}
?>

Logged

Joachim Müller

  • Dev Team member
  • Coppermine addict
  • ****
  • Offline Offline
  • Gender: Male
  • Posts: 47843
  • aka "GauGau"
    • gaugau.de
Re: Display a random image on an external website.
« Reply #5 on: March 11, 2006, 09:47:02 pm »

moving this thread accordingly.
Logged

IamDeirdre

  • Coppermine newbie
  • Offline Offline
  • Gender: Female
  • Posts: 11
Re: Display a random image on an external website.
« Reply #6 on: March 13, 2006, 07:50:33 pm »

Pretty cool, thanks for sharing this!
Logged
Deirdre

younk

  • Coppermine novice
  • *
  • Offline Offline
  • Posts: 28
Re: Display a random image on an external website.
« Reply #7 on: March 19, 2006, 12:28:35 pm »

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?
Logged

Arnaud

  • Coppermine newbie
  • Offline Offline
  • Posts: 4
Re: Display a random image on an external website.
« Reply #8 on: March 20, 2006, 12:54:27 pm »

Hello

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

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

thanks
Logged

jayanthsharma

  • Coppermine newbie
  • Offline Offline
  • Posts: 2
Re: Display a random image on an external website.
« Reply #9 on: March 21, 2006, 09:34:31 am »

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.
Logged

Joachim Müller

  • Dev Team member
  • Coppermine addict
  • ****
  • Offline Offline
  • Gender: Male
  • Posts: 47843
  • aka "GauGau"
    • gaugau.de
Re: Display a random image on an external website.
« Reply #10 on: March 21, 2006, 05:24:47 pm »

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.
Logged

pcwfreak

  • Coppermine newbie
  • Offline Offline
  • Posts: 1
Re: Display a random image on an external website.
« Reply #11 on: March 30, 2006, 04:49:46 am »

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

TuXi

  • Coppermine newbie
  • Offline Offline
  • Posts: 9
Re: Display a random image on an external website.
« Reply #12 on: May 01, 2006, 11:50:52 pm »

Thanx ALOT!!!  :)
Logged
//TuXi

chanfuterboy

  • Coppermine newbie
  • Offline Offline
  • Posts: 11
Re: Display a random image on an external website.
« Reply #13 on: May 18, 2006, 06:04:57 pm »

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
Logged

truth005

  • Coppermine newbie
  • Offline Offline
  • Posts: 2
Re: Display a random image on an external website.
« Reply #14 on: May 23, 2006, 08:40:12 pm »

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"
Logged

justbishop

  • Coppermine novice
  • *
  • Offline Offline
  • Gender: Female
  • Posts: 20
    • a-pathetic.net/ashley
Re: Display a random image on an external website.
« Reply #15 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:
Code: [Select]
$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."
Logged

justbishop

  • Coppermine novice
  • *
  • Offline Offline
  • Gender: Female
  • Posts: 20
    • a-pathetic.net/ashley
Re: Display a random image on an external website.
« Reply #16 on: May 23, 2006, 09:36:57 pm »

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:
Code: [Select]
$description = '<a href="' . $link_url . $picture['pid'] . '"><img src="' . $thumb_url . '"  border="0" alt="Photo aléatoire"/></
Logged

truth005

  • Coppermine newbie
  • Offline Offline
  • Posts: 2
Re: Display a random image on an external website.
« Reply #17 on: May 23, 2006, 10:01:08 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:
Code: [Select]
$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)
Logged

justbishop

  • Coppermine novice
  • *
  • Offline Offline
  • Gender: Female
  • Posts: 20
    • a-pathetic.net/ashley
Re: Display a random image on an external website.
« Reply #18 on: May 23, 2006, 10:23:02 pm »

Yay!  Thank you  ;D
Logged

justbishop

  • Coppermine novice
  • *
  • Offline Offline
  • Gender: Female
  • Posts: 20
    • a-pathetic.net/ashley
Re: Display a random image on an external website.
« Reply #19 on: May 24, 2006, 02:48:03 am »

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.
Logged
Pages: [1] 2 3 4   Go Up
 

Page created in 0.048 seconds with 20 queries.