www.webdeveloper.com
Results 1 to 2 of 2

Thread: generate random width of img

Hybrid View

  1. #1
    Join Date
    Feb 2011
    Posts
    47

    generate random width of img

    hi, im using this code that displays X amount of images from a facebook page. the width and height is preset. Id like to generate the width for each image, so that all images would have different sizes when they are displayed.

    Id also like to set a max width and a min width, so no images are larger than 200px and smaller than 40px, so they can be in any size between 40 and 200 px.


    PHP Code:
    <div id="fotobook-photos-widget">
      <?php foreach($photos as $photo): ?>
      <div class="thumbnail" style="height: <?php echo $size ?>px; width: <?php echo $size ?>px">
       
          <img src="<?php echo $photo['src'?>" alt="<?php echo htmlentities($photo['caption'], ENT_QUOTES?>" />
        </a>
      </div>
      <?php endforeach; ?>
    </div>

  2. #2
    Join Date
    May 2012
    Posts
    37
    I guess you could just use rand();

    PHP Code:
    $min 40;
    $max 200;
    $width rand($min,$max); 

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center



Recent Articles