Php generate small figure _ php generate thumbnail code

Source: Internet
Author: User

Php generates a thumbnail _ php generates a thumbnail code. This is a typical and practical php code for generating a thumbnail. For a professional plain language, php generates a thumbnail code.

Generate thumbnail code in php tutorial _ php
This is a typical and practical php code used to generate small images. For a professional plain language, php generates thumbnail code.
*/


# Display graphics and connections

 

Function showdir ($ adirectory, $ I)

{
Global $ browsedir;

$ Start = $ I;

# Changing $ maxcols and $ maximages can change the number of rows and columns of the small graph displayed on each page.

$ Maxcols = 2;
$ Maximages = 6;
$ Maximages = $ I + ($ maximages-3 );

# Changing $ imagemaxwidth and $ imagemaxheight can change the width and height of a 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 "<br> <center> <font face =" verdana, arial, helvetica, sans-serif "size =" 1 "color =" #000033 "> page :";

$ Pg_num = 1;

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

If ($ pg = $ img_num ){
Echo "<span class =" menulink_1 "> <a href =" thumb. php? Browsedir = $ browsedir & start = $ img_num "> * $ pg_num </a> <span> ";
} Else {
Echo "<span class =" menulink_2 "> <a href =" thumb. php? Browsedir = $ browsedir & start = $ img_num "> $ pg_num </a> <span> ";
}

# Create connections for other pages. Four graphs are displayed on each page. Therefore, the number of pages $ pg_num is increased by 1 and $ img_num is increased by 4.

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

}

Echo "</font> 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

# The variable $ browsedir is the position where the graphic file is placed.

$ Browsedir = "./images ";

# The graphic file extensions that can be browsed are placed in arrays and can be added on your own.

$ Extensions [1] = "jpeg ";
$ Extensions [2] = "jpg ";
$ Extensions [3] = "gif ";
$ Extensions [4] = "png ";
Showdir (dirtoarray ($ browsedir, $ extensions), $ start );

Define ("line_break", "<br> ");
Define ("table_start", "<table width = 600> n ");
Define ("table_end", "</table> n ");
Define ("row_start", "<tr> n ");
Define ("row_end", "</tr> n ");
Define ("col_start", "<td align = center> n ");
Define ("col_end", "n </td> n ");
Define ("img_start", "Define ("img_end", "> ");
Define ("img_width", "width = ");
Define ("img_height", "height = ");
Define ("a_start", '<a href = "');
Define ("a_close", '"> ');
Define ("a_end", "</a> ");
?>

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.