Home > Backend Development > PHP Tutorial > php generate thumbnail image_php generate thumbnail image code_PHP tutorial

php generate thumbnail image_php generate thumbnail image code_PHP tutorial

WBOY
Release: 2016-07-13 10:45:27
Original
851 people have browsed it

php generate thumbnail image_php generate thumbnail image code This is a classic and practical PHP code for generating thumbnails. In professional terms, it is PHP code for generating thumbnails.

php tutorial to generate thumbnails_php generate thumbnail code
This is a classic and practical PHP code for generating thumbnails. In professional terms, it is PHP code for generating thumbnails.
*/


# Display graphics and connections

function showdir ($adirectory, $i)

{
global $browsedir;

$start = $i;

# Change $maxcols and $maximages to change the number of rows and columns of small images displayed on each page.

$maxcols = 2;
$maximages = 6;
$maximages = $i + ($maximages - 3);

# Change $imagemaxwidth and $imagemaxheight to change the width and height of the displayed thumbnail.

$imagemaxwidth = 100;
$imagemaxheight = 100;
 
# Calculate the ratio of height to width.

$imagemaxratio = $imagemaxwidth / $imagemaxheight;
 
$ndirectory = sizeof ($adirectory);
echo (table_start);
for ($i; $i<=$maximages;)
{
echo (row_start);
for ($icols=1; $icols<=$maxcols; $icols++)
{
echo (col_start);
$imagefilename = $adirectory[++$i];
If (strlen($imagefilename)>0)
           {
$imagepath = $browsedir."/".$imagefilename;
$imagesize = getimagesize ($imagepath);
            if ($imagesize)
                                                                          $imagewidth = $imagesize[0];
$imageheight = $imagesize[1];
$imageratio = $imagewidth / $imageheight;
If ($imageratio > $imagemaxratio)
                                                                               $imageoutputwidth = $imagemaxwidth;
$imageoutputheight = ceil ($imagemaxwidth/$imagewidth*$imageheight);
              }
              else if ($imageratio < $imagemaxratio)
                                                                               $imageoutputheight = $imagemaxheight;
$imageoutputwidth = ceil ($imagemaxheight/$imageheight*$imagewidth);
              } else
                                                                               $imageoutputwidth = $imagemaxwidth;
$imageoutputheight = $imagemaxheight;
           }

# Display graphics

echo (a_start.$imagepath.a_close);

echo (img_start.$imagepath.img_width.$imageoutputwidth.img_height.$imageoutputheight.img_end);

echo (line_break.$adirectory[$i]);

echo (a_end);

           }
echo (col_end);
         }
}  
echo (row_end);
}
echo (table_end);
pagemenu ($browsedir, $ndirectory, $start);

}

function pagemenu ($browsedir, $ndirectory, $pg) {

echo "

page:";

$pg_num = 1;

for ($img_num = 0; $img_num <= $ndirectory;) {

if ($pg == $img_num) {
echo " *$pg_num ";
} else {
echo " $pg_num ";
}

# Establish links to other pages, each page displays four pictures, so every time the page number $pg_num increases by 1, $img_num increases by 4.

$pg_num = $pg_num + 1;
$img_num = $img_num + 4;

}

echo "n";

}

function dirtoarray ($browsedir, $extensions)
{

$nextensions = sizeof ($extensions);
$idirectory = 0;
$directory = dir($browsedir);
 
while ($entry = $directory->read())
{
for ($i=1; $i<=$nextensions; $i++)
          {
             $compare = stristr ($entry, $extensions[$i]);
If (strlen($compare) == strlen($extensions[$i]))
                                                                                         $adirectory[++$idirectory] = $entry;
             break;
           }
        }
}
$directory->close();
return $adirectory;
}

#Main program

#Variable $browsedir is the location where the graphics file is placed.

$browsedir="./images";

# The extensions of graphics files that are allowed to be browsed are placed in the array and can be added by yourself.

$extensions[1] = "jpeg";

$extensions[2] = "jpg";
$extensions[3] = "gif";
$extensions[4] = "png";
showdir (dirtoarray ($browsedir, $extensions), $start);

define ("line_break", "
");

define ("table_start", "

n");
define ("table_end", "
n");
define ("row_start", " n");
define ("row_end", " n");
define ("col_start", " n ");
define ("col_end", "n n");
define ("img_start", "");
define ("img_width", " width=");
define ("img_height", " height=");
define ("a_start", '');
define ("a_end", "
");
?>

http://www.bkjia.com/PHPjc/633031.htmlwww.bkjia.comtruehttp: //www.bkjia.com/PHPjc/633031.htmlTechArticlephp generate thumbnails_php generate thumbnail code This is a classic and practical php code to generate thumbnails. In professional terms, it is PHP code to generate thumbnails. php tutorial to generate small pictures_php student...
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template