CodeIgniter is a set of application development frameworks and toolkits that are used by developers of PHP Web sites.
CodeIgniter is a simple and fast PHP MVC framework. Ellislab's staff released the CodeIgniter. After many companies have tried to experience all of the PHP MVC frameworks, CodeIgniter is a winner, largely because it provides the organization with enough free support to allow developers to work more quickly.
Freedom means that when you use CodeIgniter, you do not have to name the database tables in some way, and you do not have to name the model according to the table. This makes CodeIgniter an ideal choice for refactoring legacy PHP applications, where there may be all the strange structures that need to be ported.
This article mainly introduces the method of CodeIgniter to realize the intelligent cropping image, which can not distort after cropping, and keep the theme meaning of the picture as much as possible. A friend you need can refer to the following
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.
The method I used:
1. First, the picture is shortened to the size that can be cropped;
In the case of a wide-format image, zoom to height by height = 240px, narrow picture (height greater than width) is scaled by width, etc.
2. Center crop by the long width format;
Keep the middle part of the image after the thumbnail;
$this->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 '] = 240; $config [' height '] = 240; $this->image_lib->initialize ($config); $this->image_lib->resize (); $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 ();