This article is a detailed introduction of the PHP implementation of the image upload, clipping function of the specific code for your reference, the specific content 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 ')); }/** * Home */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_err ORS ()); $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 the whole content of this article, I hope that you learn PHP programming help.
The above describes the PHP implementation of the image upload, clipping, including the image upload, PHP content, I hope that the PHP tutorial interested in a friend helpful.