Image upload: php allows you to upload and cut images. this example introduces the code for php to upload and cut images for your reference, the specific content is as follows. lo This article introduces the code for php to implement image upload and cut functions 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 | jp G | 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.
The above introduces the php image upload and cut functions, including image upload and php content, and hopes to help those who are interested in PHP tutorials.