CodeIgniter the way to realize the intelligent cropping picture _php Tutorial

Source: Internet
Author: User
Tags codeigniter
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;

Copy the 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 ();

http://www.bkjia.com/PHPjc/788628.html www.bkjia.com true http://www.bkjia.com/PHPjc/788628.html techarticle 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 and other proportions to be cut ...

  • Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.