php实现图片上传、剪切功能

本文实例为大家详细介绍了PHP实现图片上传、剪切功能的具体代码,供大家参考,具体内容如下

rush:PHP;"> class Index extends MY_Controller {
function construct(){
parent::
construct();
$this->load->helper(array('form','url'));
}

/**

  • 首页
    */
    public function index() {
    $this->load->view('upload_form',array('error' => ' ' ));
    }

public function do_upload()
{
$config['upload_path'] = './data/uploads/';
$config['allowed_types'] = 'gif|jpg|png';
$config['max_size'] = 100;
$config['max_width'] = 1024;
$config['max_height'] = 768;

$this->load->library('upload',$con<a href="https://www.jb51.cc/tag/fig/" target="_blank" class="keywords">fig</a>);

if ( ! $this->upload->do_upload('userfile'))
{
  $error = array('error' => $this->upload-><a href="https://www.jb51.cc/tag/dis/" target="_blank" class="keywords">dis</a>play_errors());

  $this->load->view('upload_form',$error);
}
else
{
  $data = array('upload_data' => $this->upload->data());

  $this->load->library('image_lib');      
  list($width,$height) = ge<a href="https://www.jb51.cc/tag/timage/" target="_blank" class="keywords">timage</a>size($data['upload_data']['full_path']);
  $con<a href="https://www.jb51.cc/tag/fig/" target="_blank" class="keywords">fig</a>['image_library'] = 'gd2';
  $con<a href="https://www.jb51.cc/tag/fig/" target="_blank" class="keywords">fig</a>['source_image'] = $data['upload_data']['full_path'];
  $con<a href="https://www.jb51.cc/tag/fig/" target="_blank" class="keywords">fig</a>['maintain_ratio'] = TRUE;
  if($width >= $height)
  {
    $con<a href="https://www.jb51.cc/tag/fig/" target="_blank" class="keywords">fig</a>['master_dim'] = 'height';
  }else{
    $con<a href="https://www.jb51.cc/tag/fig/" target="_blank" class="keywords">fig</a>['master_dim'] = 'width';
  }
  $con<a href="https://www.jb51.cc/tag/fig/" target="_blank" class="keywords">fig</a>['width'] = 180;
  $con<a href="https://www.jb51.cc/tag/fig/" target="_blank" class="keywords">fig</a>['height'] = 180;
  $this->image_lib->initialize($con<a href="https://www.jb51.cc/tag/fig/" target="_blank" class="keywords">fig</a>);
  $this->image_lib->resize();

  $con<a href="https://www.jb51.cc/tag/fig/" target="_blank" class="keywords">fig</a>['maintain_ratio'] = FALSE;
  if($width >= $height)
  {
    $con<a href="https://www.jb51.cc/tag/fig/" target="_blank" class="keywords">fig</a>['x_axis'] = floor(($width * 180 / $height - 180)/2);
  }else{
    $con<a href="https://www.jb51.cc/tag/fig/" target="_blank" class="keywords">fig</a>['y_axis'] = floor(($height * 180 / $width - 180)/2);
  }
  $this->image_lib->initialize($con<a href="https://www.jb51.cc/tag/fig/" target="_blank" class="keywords">fig</a>);
  $this->image_lib->crop();

  $this->load->view('upload_success',$data);
}

}
}

以上就是本文的全部内容,希望对大家学习PHP程序设计有所帮助。

相关文章

统一支付是JSAPI/NATIVE/APP各种支付场景下生成支付订单,返...
统一支付是JSAPI/NATIVE/APP各种支付场景下生成支付订单,返...
前言 之前做了微信登录,所以总结一下微信授权登录并获取用户...
FastAdmin是我第一个接触的后台管理系统框架。FastAdmin是一...
之前公司需要一个内部的通讯软件,就叫我做一个。通讯软件嘛...
统一支付是JSAPI/NATIVE/APP各种支付场景下生成支付订单,返...