Generate thumbnails and display with thinkphp implementation

Source: Internet
Author: User

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

Related Article

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.