This article mainly introduces in detail php's function of uploading and cutting Images Based on CodeIgniter, which is of reference value, if you are interested, you can refer to the examples in this article to share with you the codeigniter image uploading, cropping, and controller classes for your reference. The specific content is as follows:
<? Phpdefined ('basepath') OR exit ('no direct script access allowed'); class Index extends MY_Controller {function _ construct () {parent :__ construct (); $ this-> load-> helper (array ('form', 'url');}/*** homepage */public function index () {$ this-> load-> view ('upload _ Form', array ('error' => '');} public function do_upload () {$ config ['upload _ path'] = '. /data/uploads/'; $ config ['allowed _ types'] = 'gif | jpg | Png '; $ config ['max _ size'] = 100; $ config ['max _ width'] = 1024; $ config ['max _ height'] = 768; $ this-> load-> library ('upload', $ config); if (! $ This-> upload-> do_upload ('userfile') {$ error = array ('error' => $ this-> upload-> display_errors ()); $ this-> load-> view ('upload _ Form', $ error );} else {$ data = array ('upload _ data' => $ this-> upload-> data ()); $ this-> load-> library ('image _ lib'); list ($ width, $ height) = getimagesize ($ data ['upload _ data'] ['full _ path']); $ config ['image _ library'] = 'gd2 '; $ config ['source _ image'] = $ data ['upload _ data'] ['full _ path']; $ config ['maintain _ ratio '] = TRUE; if ($ width >=$ height) {$ config ['master _ dim'] = 'height ';} else {$ config ['master _ dim'] = 'width';} $ config ['width'] = 180; $ config ['height'] = 180; $ this-> image_lib-> initialize ($ config); $ this-> image_lib-> resize (); $ config ['maintain _ ratio '] = FALSE; if ($ width >=$ height) {$ config ['x _ axis '] = floor ($ width * 180/$ height-180)/2 );} else {$ config ['y _ axis '] = floor ($ height * 180/$ width-180)/2 );} $ this-> image_lib-> initialize ($ config); $ this-> image_lib-> crop (); $ this-> load-> view ('upload _ success ', $ data );}}}
The above is all the content of this article. I hope it will help you learn php programming.