php ci 处理图片 裁剪,Codeigniter实现智能裁剪图片的方法
一副1024*768大小的圖片,裁剪到240*240大小,裁剪后不失真,盡可能保留圖片主題含義。
我使用到的方法:
1. 先將圖片等比例縮略到可以裁剪的大小;
如果是寬幅圖片,則按高度等比例縮放到高度 = 240px,窄幅圖片(高度大于寬度)則按寬度等比例縮放;
2. 按長寬格式居中裁剪;
保留縮略后的圖片中間部分;
$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();
與50位技術專家面對面20年技術見證,附贈技術全景圖總結
以上是生活随笔為你收集整理的php ci 处理图片 裁剪,Codeigniter实现智能裁剪图片的方法的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 年度汇算清缴怎么操作
- 下一篇: 中储智运是不是国企