Php generate small figure _ php generate thumbnail code _ PHP Tutorial

Source: Internet
Author: User
Php generates the thumbnail code. 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. Php Tutorial generate small figure _ php generate thumbnail code this is a classic and Practical php code for generating small pictures, there is a professional plain language that is php generate thumbnail code Oh.

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"

Page :";

$ Pg_num = 1;

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

If ($ pg = $ img_num ){
Echo "* $ pg_num ";
} Else {
Echo "$ pg_num ";
}

# 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 "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 ","
");
Define ("table_start ","


N ");Define ("table_end ","
N ");
Define ("row_start ","N ");
Define ("row_end ","N ");
Define ("col_start ","N ");
Define ("col_end", "nN ");
Define ("img_start", "define (" img_end ","> ");
Define ("img_width", "width = ");
Define ("img_height", "height = ");
Define ("a_start", 'Define ("a_close", '"> ');
Define ("a_end ","");
?>

Generating thumbnail code by using Notepad is a typical and Practical php code for generating small images. if you have a professional plain language, php will generate the thumbnail code. Php Tutorial generation fig _ php...

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.