Home >Backend Development >PHP Tutorial >How to implement smart cropping of images with Codeigniter_PHP tutorial

How to implement smart cropping of images with Codeigniter_PHP tutorial

WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWB
WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOriginal
2016-07-13 10:28:251059browse

A picture of size 1024*768, cropped to size 240*240, without distortion after cropping, and retain the theme and meaning of the picture as much as possible.

The method I used:

1. First scale down the image to a size that can be cropped;

If it is a wide picture, it will be scaled to height = 240px. If it is a narrow picture (height is greater than its width), it will be scaled in proportion to width;

2. Center crop according to length and width format;

Keep the middle part of the thumbnail image;

Copy code The code is 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->crop();



http://www.bkjia.com/PHPjc/788628.html

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/788628.htmlTechArticleA picture of 1024*768 size, cropped to 240*240 size, no distortion after cropping, keep it as much as possible Image theme meaning. The method I used: 1. First reduce the picture to the same proportion so that it can be cropped...
Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn