_php examples of common image processing methods for CI frame encapsulation (thumbnail, watermark, rotation, upload, etc.)

Source: Internet
Author: User
Tags file upload codeigniter zend framework

This paper illustrates the common image processing methods of CI framework encapsulation. Share to everyone for your reference, specific as follows:

In fact, micro-letter phone on the map, the list diagram is best thumbnail, save flow, this is not, and was moved a hole, the bill to sign a stop, traffic owed to 90 to stop, I was drunk ...

Do not say nonsense, the following is the use of the built-in image of the library to write, the little brother, the omission of the place please point out, thank you.

/** * Generate thumbnail * @param $path the local path to the original image * @return Null to create an original _thumb. FILE * */Public Function Dealthumb ($path) {$conf
    ig[' image_library '] = ' gd2 ';
    $config [' source_image '] = $path;
    $config [' create_thumb '] = TRUE;
    The resulting thumbnail will be close to the width and height of the set on the widths and heights of the vertical and horizontal proportions $config [' maintain_ratio '] = TRUE;
    $config [' width '] = 80;
    $config [' height '] = 80;
    $this->load->library (' Image_lib ', $config);
    $this->image_lib->resize ();
$this->image_lib->clear ();
    /* * Processing image Rotation/Public function transroate ($path, $imgpath) {$this->load->library (' image_lib ');
    (must) set the image library $config [' image_library '] = ' gd2 '; $newname = Time (). '
    _rote.jpg ';
    Sets the target name/path of the image $config [' new_image '] = $imgpath. $newname;
    (must) set the original image name/path $config [' source_image '] = $path;
    Determines whether the new image is generated to be written to the hard disk or dynamically $config [' dynamic_output '] = FALSE; Sets the quality of the image.
    The higher the quality, the larger the image file $config [' quality '] = ' 90% '; There are 5 rotation options counterclockwise 90 180 270 degree VRT vertical flip hor sideways flip $config [' RotAtion_angle '] = ' VRT ';
    $this->image_lib->initialize ($config);
      if (@ $this->image_lib->rotate ()) {$this->image_lib->clear ();
    return $config [' New_image '];
      }else{$this->image_lib->clear ();
    Return ";
    /** * Processing image watermark/Public Function overlay ($path, $imgpath) {$this->load->library (' image_lib '); $newname = Time (). '
    _over.jpg ';
    Sets the new image name $config [' new_image '] = $imgpath. $newname;
    Invoke the PHP GD library drawing $config [' image_library '] = ' gd2 ';
    Source image Local Address $config [' source_image '] = $path;
    Cover text $config [' wm_text '] = ' Copyright 2015-friker ';
    Overlay type text/image $config [' wm_type '] = ' text ';
    Text font type//$config [' wm_font_path '] = ' C:\Windows\Fonts\vrinda.ttf ';
    Font size $config [' wm_font_size '] = ' 16 ';
    Font color $config [' wm_font_color '] = ' ff0000 ';
    The vertical distance from the top $config [' wm_vrt_alignment '] = ' 20 ';
    The horizontal direction distance from the left end $config [' wm_hor_alignment '] = ' center '; padding $config[' wm_padding '] = ' 20 ';
    $this->image_lib->initialize ($config);
      if ($this->image_lib->watermark ()) {$this->image_lib->clear ();
    return $config [' New_image '];
      }else{$this->image_lib->clear ();
    Return ";
    }/** * Processing picture upload * File Upload class via foreground upload file/Public function UploadFile () {//File upload part//process file//$data = ';
    $this->load->helper (' url ');
    $formpic = key ($_files); File Processing section if (false = = Empty ($_files[$formpic] [' tmp_name ']) {//Set file upload path $upload [' upload_path '] = "./publi
      c/img/";
      Limit the type of file uploads $upload [' allowed_types '] = ' jpeg|jpg|gif|png ';
      Limit the size of file uploads $upload [' max_size '] = 2048;
      Set the path of the file upload $upload [' file_name '] = date (' Ymdhis ', Time ()). Rand (10000, 99999);
      Loading file upload configuration information $this->load->library (' upload ', $upload);
      Processing file Upload $this->upload->do_upload ($formpic);
      Return file upload information $image = $this->upload->data ();
    /*   ' file_name ' => string ' 2015071702051718388.jpg ' (length=23) ' File_type ' => string ' image/jpeg ' (length=10) ' File_path ' => string ' e:/wamp/www/testci/public/img/' (length=30) ' Full_path ' => string ' e:/wamp/www
       /testci/public/img/2015071702051718388.jpg ' (length=53) ' raw_name ' => string ' 2015071702051718388 ' (length=19) ' Orig_name ' => string ' 2015071702051718388.jpg ' (length=23) ' client_name ' => string ' u=415761610,154833 8330&fm=116&gp=0.jpg ' (length=38) ' File_ext ' => string '. jpg ' (length=4) ' File_size ' => float 3.74 ' Is_image ' => boolean true ' image_width ' => int 146 ' image_height ' ' => int ' I
       Mage_type ' => string ' jpeg ' (length=4) ' image_size_str ' => string ' width= ' 146 ' height= ' (length=24)
      * *//var_dump ($image);
      Return file Upload name $data = $image [' file_name '];
      $this->dealthumb ($image [' Full_path ']); $this->overlay ($image [' Full_path '], $image [' File_path ']);
      $this->transroate ($image [' Full_path '], $image [' File_path ']);//$thumbdata = ';
      Generate thumbnail name $pos = Strripos ($image [' file_name '], "."); $newname = substr ($image [' file_name '], 0, $pos). "
      _thumb ". substr ($image [' file_name '], $pos);
      if (file_exists ($image [' File_path ']. $newname)) {$thumbdata = $newname;
    }//$dirroot = $_server[' Document_root ']; $this->dealthumb ($dirroot.)
    /public/img/". $data); Upload failed if (! $data) {echo json_encode (' status ' =>0, ' msg ' => ' upload failed!)
    ")); }else{//Upload succeeded Echo json_encode (Array (' name ' => $data, ' pic ' =>base_url (). "
    public/img/". $data, ' picthumb ' => $thumbdata = = '? $data: $thumbdata));

 }
}

The

Below is the basic HTML code for the front-end:

<!doctype html>  

More interested in CodeIgniter related content readers can view the site topics: "CodeIgniter Introductory Course", "CI (CodeIgniter) Framework Advanced Course", "PHP Excellent Development Framework Summary", "thinkphp Introductory Course", " Thinkphp Common Methods Summary, "Zend Framework Introduction Course", "PHP object-oriented Programming Introduction Course", "Php+mysql Database operation Introduction Tutorial" and "PHP common database Operation Skills Summary"

I hope this article will help you with the PHP program design based on CodeIgniter framework.

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.