thinkphp upload Image Automatic compression problem

Source: Internet
Author: User

Thinkphp after uploading a picture because the picture needs to be cut, but because most browsers block the clipping pop-up window cannot cut

Therefore, the use of thinkphp to generate thumbnails of the function, upload the same time directly generated thumbnails and cover the original image, so that you can customize the size of the uploaded picture (note, generated thumbnails are scaled by the original scale)

The code is as follows

Public function upload ($action) {     $upload  = new \think\upload () ; $upload->maxsize = 2097172; $upload->exts = array (' jpg ', ' gif ', ' PNG ', ' jpeg '); $upload- >savePath =  '/public/uploads/'; $info  =  $upload->upload (); foreach ($info  as  $file) {     $name  =  $file [' Savepath ']. $file [' Savename '];      }     $this->assign (' action ', $action);     $this->assign (' Name ', $name);     if (! $info) {    $this->error ($upload->geterror ());} else{//generate thumbnails $image = new \think\image (); $image->open ("./uploads{$name}");                          //  generate a thumbnail with a maximum of 150*150 as the original image and save as thumb.jpg                          $image->thumb (800, 800) ->save ("./uploads{$name}");//Direct thumbnail overlay to the original $this->display (' image ');}  }


thinkphp upload Image Automatic compression problem

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.