A pair of 1024*768 size pictures, cropped to 240*240 size, not distorted after cropping, as far as possible to retain the theme meaning of the picture.
The method I used:
1. First the picture and so on to the scale of the size can be cropped;
If it is a wide picture, then the height of the scale to height = 240px, a narrow picture (height is greater than width) by width and so on scale;
2. Cut the center by the long width format;
Retain the middle portion of the thumbnail after the picture;
Copy Code code as follows:
$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 ();