GoFuckYourself.com - Adult Webmaster Forum

GoFuckYourself.com - Adult Webmaster Forum (https://gfy.com/index.php)
-   Fucking Around & Business Discussion (https://gfy.com/forumdisplay.php?f=26)
-   -   Simple image rotation script (https://gfy.com/showthread.php?t=1094604)

nico-t 12-30-2012 05:31 AM

Simple image rotation script
 
Been looking all over for this. But all i see is script rotating 1 image.

i've got about a 100 images.
I want to display for example 5 of these images randomly every page load (without doubles).
If some images get repeated onload it doesnt matter, as long as there aren't doubles in every row of 5.
All the pics need to link to a unique url too.

Suggestions?

DWB 12-30-2012 05:33 AM

WOJ has a simple script that will do exactly that.

Oracle Porn 12-30-2012 05:42 AM

Option 1: http://ma.tt/scripts/randomimage/

Option 2: http://randaclay.com/tips-tools/mult...ge-php-script/

Option 3:
Code:

<?php
define('BASE_DIR', '/var/www/mysite/images/'); // Where are your images?
define('IMAGE_LIMIT', 10); // how many images to show?

$files    = glob(BASE_DIR.'*');
$images = Array();

if(empty($files)) {
    die("Hey, dude, there are no files. What happened?");
}

foreach($files as $v) {
    if(is_dir($v)) {
        foreach($files as $v) { // This should be a function which can loop through further sub directories if needed
            //get exif image type, if it's an image append to array
            $images[] = $v;
        }
    } else {
        $images[] = $v;
    }
}

shuffle($images); // Randomise the array
for($i=0;$i<IMAGE_LIMIT;$i++) {
    $img = $images[$i];
    if(empty($img)) {
        break; // Might be best doing a foreach above whilst keeping $i as a loop counter and breaking the loop once you reach the limit
    }
    $img_src = end(explode("/", $img));
    echo "<img src='{$img_src}'/>";
}


seeandsee 12-30-2012 05:50 AM

Quote:

Originally Posted by Oracle Porn (Post 19396546)
Option 1: http://ma.tt/scripts/randomimage/

Option 2: http://randaclay.com/tips-tools/mult...ge-php-script/

Option 3:
Code:

<?php
define('BASE_DIR', '/var/www/mysite/images/'); // Where are your images?
define('IMAGE_LIMIT', 10); // how many images to show?

$files    = glob(BASE_DIR.'*');
$images = Array();

if(empty($files)) {
    die("Hey, dude, there are no files. What happened?");
}

foreach($files as $v) {
    if(is_dir($v)) {
        foreach($files as $v) { // This should be a function which can loop through further sub directories if needed
            //get exif image type, if it's an image append to array
            $images[] = $v;
        }
    } else {
        $images[] = $v;
    }
}

shuffle($images); // Randomise the array
for($i=0;$i<IMAGE_LIMIT;$i++) {
    $img = $images[$i];
    if(empty($img)) {
        break; // Might be best doing a foreach above whilst keeping $i as a loop counter and breaking the loop once you reach the limit
    }
    $img_src = end(explode("/", $img));
    echo "<img src='{$img_src}'/>";
}


Hi, thanks for this code. Can you point me to some good php tutorial site, i have experience in programing (c, c++, basic, even pascal) but i need good site to learn some step by step php code?

just a punk 12-30-2012 05:53 AM

Assuming that all image URL's are stored in "images.txt" (one URL per line), the code will be as simple as this:
Code:

$images = file('images.txt');
shuffle($images);
for ($i = 0; $i < min(5, count($images)); $i++) {
    echo '<img src="' . trim($images[$i]) . '" />';
}


nico-t 12-30-2012 06:33 AM

Quote:

Originally Posted by Oracle Porn (Post 19396546)
Option 1: http://ma.tt/scripts/randomimage/

Option 2: http://randaclay.com/tips-tools/mult...ge-php-script/

Option 3:
Code:

<?php
define('BASE_DIR', '/var/www/mysite/images/'); // Where are your images?
define('IMAGE_LIMIT', 10); // how many images to show?

$files    = glob(BASE_DIR.'*');
$images = Array();

if(empty($files)) {
    die("Hey, dude, there are no files. What happened?");
}

foreach($files as $v) {
    if(is_dir($v)) {
        foreach($files as $v) { // This should be a function which can loop through further sub directories if needed
            //get exif image type, if it's an image append to array
            $images[] = $v;
        }
    } else {
        $images[] = $v;
    }
}

shuffle($images); // Randomise the array
for($i=0;$i<IMAGE_LIMIT;$i++) {
    $img = $images[$i];
    if(empty($img)) {
        break; // Might be best doing a foreach above whilst keeping $i as a loop counter and breaking the loop once you reach the limit
    }
    $img_src = end(explode("/", $img));
    echo "<img src='{$img_src}'/>";
}


I'm using the 3rd option now, and added some code to display unique links for every image begin shown, between these last lines of code:
Code:

    $img_src = end(explode("/", $img));
    echo "<img src='{$img_src}'/>";
}

\

I have added some lines to assign imagename to the url for each pic like i was planning to:
Code:

    $img_src = end(explode("/", $img));
    $imgid = basename($img, ".jpg");
    echo "<a href='http://www.mydomain/id=$imgid'><img src='{$img_src}'/></a>";
}
?>

And it works exactly like i wanted! Thanks a lot for helping me out :thumbsup

Oracle Porn 12-30-2012 07:30 AM

you mind posting the entire edited code? :)
thanks

Oracle Porn 12-30-2012 07:31 AM

Quote:

Originally Posted by seeandsee (Post 19396559)
Hi, thanks for this code. Can you point me to some good php tutorial site, i have experience in programing (c, c++, basic, even pascal) but i need good site to learn some step by step php code?

I use this site

nico-t 12-30-2012 07:32 AM

one thing i noticed. About the above code.

When you have your scriptcode.php in the same folder as the images, the rotator sometimes grabs the .php file too.

When i put the scriptcode.php in a parent folder:
/mysite/script/scriptcode.php
And the images in:
/mysite/script/images/image.jpg

The script looks for the images in /mysite/script/ like it doesn't see the images folder.
I have put the correct image path in the script. Think it has something to do with the explode code?

nico-t 12-30-2012 08:23 AM

fixed the above by just adding images dir before the img src output.


Quote:

Originally Posted by Oracle Porn (Post 19396638)
you mind posting the entire edited code? :)
thanks

ofcourse, here it is.
script is at:
mysite.com/script/script.php
Images in:
mysite.com/script/images/

Code:
Code:

<?php
define('BASE_DIR', '/home/user/domains/mysite.com/public_html/script/images/'); // Where are your images?
define('IMAGE_LIMIT', 5); // how many images to show?

$files    = glob(BASE_DIR.'*');
$images = Array();

if(empty($files)) {
    die("Hey, dude, there are no files. What happened?");
}

foreach($files as $v) {
    if(is_dir($v)) {
        foreach($files as $v) { // This should be a function which can loop through further sub directories if needed
            //get exif image type, if it's an image append to array
            $images[] = $v;
        }
    } else {
        $images[] = $v;
    }
}

shuffle($images); // Randomise the array
for($i=0;$i<IMAGE_LIMIT;$i++) {
    $img = $images[$i];
    if(empty($img)) {
        break; // Might be best doing a foreach above whilst keeping $i as a loop counter and breaking the loop once you reach the limit
    }
    $img_src = end(explode("/", $img));
    $imgid = basename($img, ".jpg");
    echo "<a href='http://www.mysite.com/id=$imgid'><img src='images/{$img_src}'/></a>";
}
?>

Takes filename of pic (which is also the url ID) to link every pic to its own ID page.

Barry-xlovecam 12-30-2012 09:07 AM

nvm ..... read the image part

fitzmulti 12-30-2012 09:54 AM

Neat code to have. Thanks!


All times are GMT -7. The time now is 01:46 PM.

Powered by vBulletin® Version 3.8.8
Copyright ©2000 - 2025, vBulletin Solutions, Inc.
©2000-, AI Media Network Inc123