First understand some of the functions in the parent class Image.class.php (thinkphp/library/think/image.class.php)
1: Open() opened the processed picture
2:thumb () generate thumbnail default 1 zoom (where 2,3,4,5,6 represents the meaning of the parent class file Image.class.php)
3:Save () thumbnail to server
Create a thumbnail step in the following four steps
* 1. Instantiation
* 2. Open the picture ()
* 3. Generate thumbnail thumb () Default zoom
* 4. Save ()
Controller code:
// Large Map path (here The big map Path can refer to the upload path of "Upload with thinkphp for attachments" )
$bigimg _path=$upload->rootpath.$file _info[' Savepath '].$file _info[' Savename '];//Small Map Path$smallimg _path=$upload->rootpath.$file _info[' Savepath ']. ' Small_ '.$file _info[' Savename '];$img=New\think\image ();//instantiation of$img->open ($bigimg _path);//open a picture that is processed$img->thumb (100,100);//making thumbnails (100*100)$img->save ($smallimg _path);//save thumbnails to server//upload good attachments and thumbnail survival to the database$_post[' Goods_big_img ']=$bigimg _path;$_post[' Goods_small_img ']=$smallimg _path;
Entry File Set Constants
Display thumbnail path for foreground convenient, set constant in portal file index.php, indicate site path, and database store picture path stitching
Define (' Site_url ', ' http://www.tp.com/TP/shop/');
Large map and thumbnail display at the front desk
<TD><!--Big Picture - <imgsrc= "<{$smarty. const.site_url}><{$v .goods_big_img}>"Height= "$"width= "$"></TD><TD><!--Small Map - <imgsrc= "<{$smarty. const.site_url}><{$v .goods_small_img}>"Height= "Max"width= "Max"></TD>
Results
Storing paths in the database
Image
Front desk Display
Generate thumbnails and display with thinkphp implementation