Looking for a rotation script

Discussion in 'PHP' started by tony84, Nov 17, 2008.

  1. #1
    I want it to be able to rotate between 3-5 images with a text description.

    Ideally just something basic like xml or text file as for the time being it doesnt need to be mysql.

    Cheers
     
    tony84, Nov 17, 2008 IP
  2. Colbyt

    Colbyt Notable Member

    Messages:
    3,224
    Likes Received:
    185
    Best Answers:
    0
    Trophy Points:
    210
    #2
    Have you looked at PHP using random() to pick 1-X and then switch to load the random pick?

    No mysql involved. Just 3-4 lines of code per pick.
     
    Colbyt, Nov 17, 2008 IP
  3. ads2help

    ads2help Peon

    Messages:
    2,142
    Likes Received:
    67
    Best Answers:
    1
    Trophy Points:
    0
    #3
    Try this and do some customisation
     
    ads2help, Nov 17, 2008 IP
  4. tony84

    tony84 Well-Known Member

    Messages:
    1,864
    Likes Received:
    29
    Best Answers:
    0
    Trophy Points:
    140
    #4
    Thats a nice simple script, I have 2 questions, how do i customise it to add the comment and is there a way to ensure the picture only displays at a certain size?
     
    tony84, Nov 18, 2008 IP
  5. ads2help

    ads2help Peon

    Messages:
    2,142
    Likes Received:
    67
    Best Answers:
    1
    Trophy Points:
    0
    #5
    To add the comment, (slightly modified from the original)

    
    // array of images
    $image_db = array(
    1 => 'link_to_picture_1',
    'link_to_picture_2',
    'link_to_picture_3',
    'link_to_picture_4',
    'link_to_picture_5',
    );
    
    // array of comments
    $comment_db = array(
    1 => 'COMMENT_FOR_IMAGE_1',
    'COMMENT_FOR_IMAGE_2',
    'COMMENT_FOR_IMAGE_3',
    'COMMENT_FOR_IMAGE_4',
    'COMMENT_FOR_IMAGE_5',
    );
    
    // generate a random number
    $rand = rand(1,count($image_db));
     
    // finally, print image
    print '<img src="' . $image_db[$rand] . '" />';
    // print comment below it
    print '<br />'.$comment_db[$rand];
    
    PHP:
    Regarding this
    what you mean was limiting the size of the image?
     
    ads2help, Nov 18, 2008 IP
  6. tony84

    tony84 Well-Known Member

    Messages:
    1,864
    Likes Received:
    29
    Best Answers:
    0
    Trophy Points:
    140
    #6
    The height and width i want to be a maximum of about 150-200px
     
    tony84, Nov 18, 2008 IP
  7. ads2help

    ads2help Peon

    Messages:
    2,142
    Likes Received:
    67
    Best Answers:
    1
    Trophy Points:
    0
    #7
    
    $height_width_limit = '200';
    
    // array of images
    $image_db = array(
    1 => 'link_to_picture_1',
    'link_to_picture_2',
    'link_to_picture_3',
    'link_to_picture_4',
    'link_to_picture_5',
    );
    
    // array of comments
    $comment_db = array(
    1 => 'COMMENT_FOR_IMAGE_1',
    'COMMENT_FOR_IMAGE_2',
    'COMMENT_FOR_IMAGE_3',
    'COMMENT_FOR_IMAGE_4',
    'COMMENT_FOR_IMAGE_5',
    );
    
    // generate a random number
    $rand = rand(1,count($image_db));
     
    // finally, print image
    print '<img src="' . $image_db[$rand] . '" ';
    
    $img_size = getimagesize($image_db[$rand]);
    if ($img_size[0] > $height_width_limit || $img_size[1] > $height_width_limit) {
    // either width or height is bigger than $height_width_limit set above
    
    // let the browser do proportional resizing itself
    if ($img_size[0] > $img_size[1]) { // width > height , limit the size using width
    print 'width="'.$height_width_limit.'px" ';
    }
    elseif ($img_size[1] >= $img_size[0]) { // height > width , limit the size using height
    print 'height="'.$height_width_limit.'px" ';
    }
    
    }
    
    // close img tag
    print '/>';
    
    // print comment below it
    print '<br />'.$comment_db[$rand];
    PHP:
    Anyway, whats the shape of the image? square? rectangle? its width greater than height or?
     
    ads2help, Nov 18, 2008 IP
  8. tony84

    tony84 Well-Known Member

    Messages:
    1,864
    Likes Received:
    29
    Best Answers:
    0
    Trophy Points:
    140
    #8
    just photographs, so rectangle.

    That script is prety good.

    Thank you
     
    tony84, Nov 18, 2008 IP