mardi 8 septembre 2020

Auto resize images in a directory using php

There is a directory called "images" and it has some images which are large in size and does not display correctly on a browser, so i wanted to resize them so that every image is displayed in the same manner

so my code which reads the directory is like this:-

    <?php
     $files = glob("images/*.*");
     for ($i=0; $i<count($files); $i++)
      {
        $image = $files[$i];
        $supported_file = array(
                'gif',
                'jpg',
                'jpeg',
                'png'
         );

         $ext = strtolower(pathinfo($image, PATHINFO_EXTENSION));
         if (in_array($ext, $supported_file)) {
            echo basename($image)."<br />";
             echo '<img src="'.$image .'" alt="Random image" />'."<br /><br />";
            } else {
                continue;
            }
          }
       ?>



Aucun commentaire:

Enregistrer un commentaire