dcsimg
www.webdeveloper.com
Page 2 of 2 FirstFirst 12
Results 16 to 17 of 17

Thread: display images in a folder

  1. #16
    Join Date
    May 2013
    Posts
    2
    Quote Originally Posted by Henry07 View Post
    this is a php code
    <?
    $files = glob("images/*.*");
    for ($i=0; $i<count($files); $i++)
    {
    $num = $files[$i];
    echo '<img src="'.$num.'" alt="random image" />'."<br><br>";
    }
    ?>


    Duplichecker - Plagiarism software

  2. #17
    Join Date
    Mar 2007
    Location
    localhost
    Posts
    2,937
    All you need to get thumb nails is to use the getimagesize() function in conjunction with list() to obtain the height and width of the image then use a calculation to ensure that the resizing of height and width is not going to result in an image that is out of proportion.

    I used something like this for my images

    PHP Code:
    $ext = array("jpg","png","gif","bmp");
    foreach(
    $ext as $typ){
        
    $dir glob("*.{$typ}");
        
    $img array_combine$dir $img);
        }

    $ratio 0.33// approx 1/3rd

    foreach($img as $thumb){
        list(
    $width$height$type$attr) = getimagesize$thumb );
        
    $height $height $ratio;
        
    $width $width $ratio;
        echo 
    "<img height='{$height}' width='{$width}' title='' src='{$thumb}'; /><br>\r\n";    

    its been a long time since I looked at the script but thats the basics of what I did.
    STOP using $ prefix on JavaScript variable names...
    Please remember to wrap any code you have in forum tags:-

    [CODE]...[/CODE] [HTML]...[/HTML] [PHP]...[/PHP]

    If you can't think outside the box, you will be trapped forever with no escape...

Thread Information

Users Browsing this Thread

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

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