This paper introduces the method of CodeIgniter to realize the intelligent cropping picture, the picture is cropped and not distorted, as far as possible to retain the meaning of the theme of the picture, the need to refer to friends. CodeIgniter Smart crop Image A pair of 1024x768-sized pictures, cut to 240*240 size, cut not distorted, as far as possible to retain the theme of the picture. Methods: 1, the picture, such as the proportion of the thumbnail to the size can be cut, if it is a wide picture, the height of the scale to the height = 240px, narrow picture (height greater than the width) is scaled by the width of the scale; 2, according to the long-width format of the center cut, keep the thumbnail image of the middle part;
Load->library (' Image_lib '); List ($width, $height) = getimagesize ("upload/123.jpg"), $config [' image_library '] = ' gd2 '; $config [' source_image '] = ' Upload/123.jpg '; $config [' maintain_ratio '] = true;if ($width >= $height) {$config [' master_dim '] = ' height ';} else{$config [' master_dim '] = ' width ';} $config [' width '] =: $config [' height '] =->image_lib-, $this->image_lib->initialize ($config); $this >resize ();//by bbs.it-home.org$config[' maintain_ratio '] = false;if ($width >= $height) {$config [' x_axis '] = floor (($width * 240/$height-240)/2);} else{$config [' y_axis '] = Floor (($height * 240/$width-240)/2);} $this->image_lib->initialize ($config); $this->image_lib->crop ();
|