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