Register

If this is your first visit, please click the Sign Up now button to begin the process of creating your account so you can begin posting on our forums! The Sign Up process will only take up about a minute of two of your time.

Results 1 to 4 of 4
  1. #1
    Junior Member
    Join Date
    Feb 2006
    Posts
    7
    Member #
    12620
    I need a script that loads a two part image. An example of this is shown at the following site:

    http://www.g-seed.com

    The banner and the top bar consist of two images in two table cells and despite it being randomized (click refresh to see another banner), the top bar syncs with the banner image.

    So though randomized, when topbar_1.jpg is loaded, banner_1.jpg is also loaded. If topbar_2.jpg is loaded, banner_3.jpg is also loaded.

    When viewing the source of the site, it did not show any type of Javascript code, so I am assuming that this can be done with php. Maybe 2 arrays of images and storing them into two variables that are synced with each other maybe? I would really need this script and would appreciate it if anyone could help me out as I have no experience in PHP coding.

    The following are a few links with topics from various forums of conceptually what I want to have done, but cannot find the solution:

    http://www.webdeveloper.com/forum/showthread.php?t=101

  2.  

  3. #2
    Senior Member
    Join Date
    May 2003
    Location
    UK
    Posts
    2,354
    Member #
    1326
    First, welcome to WDF.

    JavaScript or PHP can do this, but heres a PHP solution.

    PHP Code:

    <?php

    $banners 
    = array(    
        
    1=>"banner1.jpg",
        
    2=>"banner2.jpg",
        
    3=>"banner3.jpg");

    $footers = array(
        
    1=>"footer1.jpg",
        
    2=>"footer2.jpg",
        
    3=>"footer3.jpg");

    $num rand(1count($banners)); 

    echo 
    "The header image to display is: $banners[$num]";
    echo 
    "<br />\nAnd the footer image to display is: $footers[$num]";
    ?>
    Demo: http://bfsog.co.uk/testing/rand-img.php

    I did not do the displaying the image part, but to add that, instead of the "The header image to display is.." line you would have..
    PHP Code:
    echo "<img src=\"$banners[$num]\" width=\"\" height=\"\" alt=\"\" />"
    And for the footer...
    PHP Code:
    echo "<img src=\"$footers[$num]\" width=\"\" height=\"\" alt=\"\" />"
    However, you would need to have the images as the same size, or have an array for the dimensions, or use getimagesize() (http://uk2.php.net/manual/en/function.getimagesize.php)

    Hope this helps.

  4. #3
    Junior Member
    Join Date
    Feb 2006
    Posts
    7
    Member #
    12620
    -------------------
    However, you would need to have the images as the same size, or have an array for the dimensions, or use getimagesize() (http://uk2.php.net/manual/en/function.getimagesize.php)
    -------------------
    The images that I will be using are indeed different sizes. Using the code you provided for the PHP way, could you show me the code or tell me as to what I would do if my images were of a different size? Im not really sure how exactly to make an array for the dimensions or use the getimagesize(). I would really appreciate it if someone could show me how to implement it.

  5. #4
    Senior Member
    Join Date
    May 2003
    Location
    UK
    Posts
    2,354
    Member #
    1326
    Heres the finished code

    PHP Code:
    <?php

    $banners 
    = array(    
        
    1=>"banner1.jpg",
        
    2=>"banner2.jpg",
        
    3=>"banner3.jpg");

    $footers = array(
        
    1=>"footer1.jpg",
        
    2=>"footer2.jpg",
        
    3=>"footer3.jpg");

    $num rand(1count($banners));

    $bannerFile getimagesize($banners[$num]);
    $bannerW $bannerFile[0];
    $bannerH $bannerFile[1];

    $footerFile getimagesize($footers[$num]);
    $footerW $footerFile[0];
    $footerH $footerFile[1];


    echo 
    "The header image to display is: $banners[$num], the width is $bannerW and the height is $bannerH"
    echo 
    "<br />\nAnd the footer image to display is: $footers[$num], the width is $footerW and the height is $footerH";

    echo 
    "<img src=\"$banners[$num]\" width=\"$bannerW\" height=\"$bannerH\" /><br />\n";
    echo 
    "<img src=\"$footers[$num]\" width=\"$footerW\" height=\"$footerH\" /><br />\n";
    ?>


Remove Ads

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
All times are GMT -6. The time now is 03:56 AM.
Powered by vBulletin® Version 4.2.3
Copyright © 2019 vBulletin Solutions, Inc. All rights reserved.
vBulletin Skin By: PurevB.com