We are using
PHP generates thumbnail HTML code
- < ! DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 transitional//en">
- < HTML>
- < HEAD>
- < TITLE> upload images < /title >
- < META NAME="Generator" CONTENT ="editplus">
- < META NAME = "Author" CONTENT = "" >
- < META NAME="Keywords" CONTENT ="">
- < META NAME = "Description" CONTENT = "">
- < meta http-equiv="Content-type" content = "text/html; CHARSET=GBK " />
- < /head >
- < BODY>
- < FORM METHOD="POST" ACTION ="tu.php?act=upload" enctype="multipart/ Form-data " >
- < p > < INPUT type = "file" name = "file" /> < /P ;
- < p > < INPUT type = "submit" value = "Hao" /> < INPUT type = "reset" /> < /P ;
- < /form >
- < /body >
- < /html >
PHP generates thumbnail PHP code
- < ? PHP
- /* Background Login interface
- * Huang Chunlong Learn to write
- * First Write Time: 2009-10-27
- * Update Time: 2009/11/24
- */
- Require_once '. /xmphp/init.php ';
- Full Station configuration file
- Require_once Xmphp_common. ' /smarty.php ';
- Smarty function
- Require_once Xmphp_common. ' /mysql.php ';
- MySQL Features
- Require_once Xmphp_common. ' /func.php ';
- Common functions
- if (Isset ($_get[' act ') &&$_get[' act ']
= = ' upload ') {
- $ file =$_files[' file ';
- $ Info = PathInfo ($file [' name ']);
- $ a = Array (' jpg ', ' gif ', ' PNG ');
- if (!in_array ($info [' extension '], $a)) {
- Alert ("Please select a picture in jpg,gif,png format
Upload ");
- Exit
- }
- if ($file [' name ']! = ') {
- $ dirname = Date (' Ym ');
- $ dirname = '.. /upload/'. $dirname;
- Original path
- $ Xin = $dirname. ' /s ';//php generate thumbnail path
- if (!file_exists ($xin)) {
- @mkdir ($xin);
- }
- $ Image1 = $info [' filename ']. ' 120_120 '. '. '
. $info [' extension '];//thumbnail name
- $ Image2 = $info [' filename ']. ' 300_300 '. '. '
. $info [' extension '];//thumbnail name
- List ($IMAGW, $imagh) =getimagesize ($file
[' Tmp_name ']); /Get the width height of the original image (another $file
[' Tmp_name '] is just a temporary file path that may sometimes
will be error, such as error only need to change the temporary file path to your upload
After the path of the original image)
- 120 figure judging various situations to obtain the width of the thumbnail image
- if ($IMAGW< =120&& $imagh< =120) {
- $ m120w = $IMAGW;
- $ m120h = $imagh;
- }elseif ($IMAGW>$imagh)
- {
- $ m120w = 120;
- $ m120h = intval ($m 120w/number_format (
$IMAGW/$imagh, 2));//The width of the thumbnail divided by (original
The width of the graph divided by the height of the original) Number_format Handbook
- }
- Else
- {
- $ m120h = - ;
- $ m120w = intval ($m 120h/number_format (
$imagh/$IMAGW, 2));//The height of the thumbnail divided by the original image
Height divided by the width of the original) Number_format search manual
- }
- 300 figure judging various situations to obtain the width of the thumbnail image
- if ($IMAGW< =300&& $imagh< =300) {
- $ m300w = $IMAGW;
- $ m300h = $imagh;
- }elseif ($IMAGW>$imagh) {
- $ m300w = 300;
- $ m300h = intval ($m 300w/number_format (
$IMAGW/$imagh, 2));//The width of the thumbnail divided by (original
The width of the graph divided by the height of the original) Number_format Handbook
- }else{
- $ m300h = 300;
- $ m300w = intval ($m 300h/number_format (
$imagh/$IMAGW, 2));//The High divide of the thumbnail (original
The height of the graph divided by the width of the original) Number_format Handbook
- }
- if ($info [' extension ']== ' jpg ') {
- $info [' extension ']= ' jpeg ';//judging the image class
If the type is JPG, convert it to JPEG because the image
The function is JPEG rather than JPG when working with JPG.
- }
- $ IML = ' Imagecreatefrom ' . $info [' extension '];
- Get different functions for different picture formats
- $ Yuan = $IML ($file [' tmp_name ']);
- Identification of the original image based on the different functions previously taken
- $ MU1 = Imagecreatetruecolor ($m 120w, $m 120h);
- The identity of the thumbnail to be generated
- $ MU2 = Imagecreatetruecolor ($m 300w, $m 300h);
- The identity of the thumbnail to be generated
- $ C = ' image ' . $info [' extension '];
- Generate output thumbnail function, cannot write separately, otherwise error
- Imagecopyresampled ($mu 1, $yuan, 0,0,0,
0, $m 120w, $m 120h, $IMAGW, $imagh);//Generate thumbnails 120
- $ Res = $c ($mu 1, $xin. ' /'. $image 1);
- Store thumbnail images
- if (! $res) {
- Alert (' Generate 120 thumbnails failed ');
- Exit
- }
- Imagecopyresampled ($mu 2, $yuan, 0,0
, 0,0, $m 300w, $m 300h, $IMAGW, $imagh);
- PHP generated thumbnail generated thumbnail image 120
- $ Res = $c ($mu 2, $xin. ' /'. $image 2);
- Store thumbnail images
- if ($res) {
- Alert (' Generate 300 thumbnail success ');
- Exit
- }
- }
- }
- $TPL- > display ("tu/tu.html");
- ?>
The above section of the code example is the implementation of the PHP generated thumbnails related methods.
http://www.bkjia.com/PHPjc/446079.html www.bkjia.com true http://www.bkjia.com/PHPjc/446079.html techarticle we are using PHP to generate thumbnail HTML code! Doctypehtmlpublic "-//w3c//dtdhtml4.0transitional//en" > HTML > HEAD > TITLE > Uploading Images/title > META NAME = "Ge Nerator "CONTENT = ...