Skip to content

Displaying images in descending order #9

Description

@TuulikkiLaine

Is it possible to get elements in descending order, as in - if more elements are added (with higher id), they would be prepended to the gallery and shown first? What would be the easiest way to do this? Thanks a lot!

Activity

  1. Bigben83 commented on Jul 31, 2018

    @Bigben83

    This is the script I use to scan a dir and list images in it. it also extracts data from the exif of the file. but you can delete this if you need.

    `<?php
    $client = (isset($_GET["client"])) ? $_GET["client"] : ""; // client number

    $directory = "directory";
    $dirname = $directory . "/" . $client . "/";
    $images = scandir($dirname);
    //shuffle($images);
    rsort($images);
    $ignore = array(".", "..");
    foreach($images as $curimg){
    	if(!in_array($curimg, $ignore)) {
    	    
    	    $currimage= "$dirname$curimg";
    	    
    	    
    	    //Gets file name
    	    $filename = basename($currimage);
    	    $author = substr($filename, 0, strpos($filename, '.', strpos($filename, '.')+1));
    	        $author = str_replace('.', ' ', $author); 
    	    $date = substr($filename, 0, strpos($filename, '.', strpos($filename, '.')+1));
    	    $title = $author;
    	    
    	    if(mime_content_type($currimage)=='video/mp4'){
                $currimage = $currimage;
    	    }else{
                // read all available tags into an associative array
                $exif_ifd0 = read_exif_data($currimage ,'IFD0' ,0);
                $exif_data = exif_read_data($currimage ,'EXIF' ,0);
                //error control
                $notFound = "Unavailable";
                
                // Date
                  if (@array_key_exists('DateTime', $exif_ifd0)) {
                    $camDate = $exif_ifd0['DateTime'];
                  } else { $camDate = $notFound; }
                // Exposure
                  if (@array_key_exists('ExposureTime', $exif_ifd0)) {
                    $camExposure = $exif_ifd0['ExposureTime'];
                  } else { $camExposure = $notFound; }
                // Aperture
                  if (@array_key_exists('ApertureFNumber', $exif_ifd0['COMPUTED'])) {
                    $camAperture = $exif_ifd0['COMPUTED']['ApertureFNumber'];
                  } else { $camAperture = $notFound; }
                // ISO
                  if (@array_key_exists('ISOSpeedRatings',$exif_exif)) {
                    $camIso = $exif_exif['ISOSpeedRatings'];
                  } else { $camIso = $notFound; }
    	    }
    	    
    		// Type contains video/mp4,video/avi,video/mpeg,video/mpg etc
            if(preg_match('/video\/*/',$currimage)){
                echo "<li>
                    <div data-alt=\"$title\" data-description=\"<h3>$title</h3><h4>$date</h4>\" data-max-width=\"1800\" data-max-height=\"1350\">
                        <video width=\"700\" height=\"450\" preload=\"true\">
                            <source src=\"$currimage\" type=\"video/mov\">
                            <source src=\"$currimage\" type=\"video/mp4\">
                            <source src=\"$currimage\" type=\"video/oog\">
                            Your browser does not support the video tag.
                        </video>
                    </div>
                </li>";
            }else{
    		    //echo "<li><a href=\"$dirname$curimg\"><img src='img.php?src=$dirname$curimg&w=300&zc=1' alt='' /></a></li>\n ";
    			echo "<li>
                        <div data-alt=\"$title\" data-description=\"<h3>$title</h3><h4>$date</h4>\" data-max-width=\"1800\" data-max-height=\"1350\">
                        <div data-src=\"$currimage\" data-min-width=\"1300\"></div>
                        <div data-src=\"$currimage\" data-min-width=\"1000\"></div>
                        <div data-src=\"$currimage\" data-min-width=\"700\"></div>
                        <div data-src=\"$currimage\" data-min-width=\"300\"></div>
                        <div data-src=\"$currimage\" data-min-width=\"200\"></div>
                        <div data-src=\"$currimage\" data-min-width=\"140\"></div>
                        <div data-src=\"$currimage\"></div>
                            <noscript><img src=\"$currimage\" alt=\"<h3>$title</h3>\"/></noscript>
                        </div>
                    </li>"; 
            };
    	}
    }`
    
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions