In-depth analysis of CodeIgniter Image Processing

Source: Internet
Author: User
Tags codeigniter

Image. php
Copy codeThe Code is as follows: <? Php
Class Image extends Controller {
Function Image ()
{
Parent: Controller ();
$ This-> load-> library ('image _ lib ');
}

// Thumbnail
Function index (){
Echo '* resize the image <br>
* Create a thumbnail <br>
* Image cropping <br>
* Image rotation <br>
* Add an image watermark <br>
';
}
// Thumbnail
Function resize (){
/*
Note:
When $ config ['create _ thumb'] is equal to FALSE and $ config ['new _ image'] is not specified, the source image size is adjusted.
When $ config ['create _ thumb'] is equal to TRUE and $ config ['new _ image'] is not specified, the generated file name is (original image name _ thumb. Extension)
When $ config ['create _ thumb'] is equal to FALSE and $ config ['new _ image'] is specified, the value of the generated file name is $ config ['new _ image '].
When $ config ['create _ thumb'] is equal to TRUE and $ config ['new _ image'] is specified, the generated file name is (original image name _ thumb. Extension)
*/
$ Config ['image _ library'] = 'gd2'; // (required) set the image library
$ Config ['source _ image'] = 'ptjsite/upload/55002.jpg '; // (required) set the name/path of the original image
$ Config ['dynamic _ output'] = FALSE; // determines whether the new image is generated by writing it to the hard disk or dynamically.
$ Config ['quality'] = '000000'; // set the image quality. Higher quality, larger image files
$ Config ['new _ image'] = 'ptjsite/upload/resize004.gif '; // set the target name/path of the image.
$ Config ['width'] = 575; // (required) set the image width you want.
$ Config ['height'] = 350; // (required) set the Image height
$ Config ['create _ thumb'] = TRUE; // Let the image processing function generate a preview image (before _ thumb is inserted into the file extension)
$ Config ['thumb _ marker'] = '_ thumb'; // specifies the marker of the preview image. It will be before the file extension to be inserted. For example, mypic.jpg will be changed to mypic_thumb.jpg.
$ Config ['maintain _ ratio '] = TRUE; // maintain the proportion
$ Config ['master _ dim'] = 'auto'; // auto, width, and height specify the main axis
$ This-> image_lib-> initialize ($ config );
If (! $ This-> image_lib-> resize ())
{
Echo $ this-> image_lib-> display_errors ();
} Else {
Echo "successful ";
}
}
// Crop images
Function crop (){
$ Config ['image _ library'] = 'gd2'; // sets the image library.
$ Config ['source _ image'] = 'ptjsite/upload/004.gif '; // (required) set the name/path of the original image
$ Config ['dynamic _ output'] = FALSE; // determines whether the new image is generated by writing it to the hard disk or dynamically.
$ Config ['quality'] = '000000'; // set the image quality. Higher quality, larger image files
$ Config ['new _ image'] = 'ptjsite/upload/crop004.gif '; // (required) set the target name/path of the image.

$ Config ['width'] = 75; // (required) set the image width you want.
$ Config ['height'] = 50; // (required) set the Image height
$ Config ['maintain _ ratio '] = TRUE; // maintain the proportion
$ Config ['x _ axis '] = '30'; // (required) pixel value retrieved from the left
$ Config ['y _ axis '] = '40'; // (required) pixel value retrieved from the header

$ This-> image_lib-> initialize ($ config );

If (! $ This-> image_lib-> crop ())
{
Echo $ this-> image_lib-> display_errors ();
} Else {
Echo "successful ";
}
}

// Image rotation
Function rotate (){
$ Config ['image _ library'] = 'gd2'; // (required) set the image library
$ Config ['source _ image'] = 'ptjsite/upload/001.jpg '; // (required) set the name/path of the original image
$ Config ['dynamic _ output'] = FALSE; // determines whether the new image is generated by writing it to the hard disk or dynamically.
$ Config ['quality'] = '000000'; // set the image quality. Higher quality, larger image files
$ Config ['new _ image'] = 'ptjsite/upload/rotate001.jpg '; // set the target name/path of the image
$ Config ['rotation _ ange'] = 'vrt '; // there are 5 rotation options: 90, 180, 270 degrees, vrt, vertical flip, hor, horizontal flip
$ This-> image_lib-> initialize ($ config );

If (! $ This-> image_lib-> rotate ())
{
Echo $ this-> image_lib-> display_errors ();
}
}

// Text watermark
Function watermark (){
$ Config ['image _ library'] = 'gd2'; // (required) set the image library
$ Config ['source _ image'] = 'ptjsite/upload/003.jpg '; // (required) set the name and path of the original image. the path must be a relative or absolute path, but not a URL.
$ Config ['dynamic _ output'] = FALSE; // TRUE dynamic existence (output image directly to the browser), FALSE written to the hard disk
$ Config ['quality'] = '000000'; // set the image quality. Higher quality, larger image files
$ Config ['new _ image'] = 'ptjsite/upload/crop004.gif '; // set the target name/path of the image.

$ Config ['wm _ type'] = 'overlay '; // (required) set the watermark processing type (text, overlay) to be used)
$ Config ['wm _ padding '] = '5'; // relative position of the image (in pixels)
$ Config ['wm _ vrt_alignment '] = 'middle'; // top, middle, bottom
$ Config ['wm _ hor_alignment '] = 'center'; // left, center, right
$ Config ['wm _ vrt_offset '] = '0'; // specify a vertical offset (in pixels)
$ Config ['wm _ hor_offset '] = '0'; // specify a horizontal offset (in pixels)
/* Text watermark parameter settings */
$ Config ['wm _ text'] = 'copyright 2008-John Doe '; // (required) watermark text content
$ Config ['wm _ font_path'] = 'ptj _ system/fonts/type-ra.ttf '; // font name and Path
$ Config ['wm _ font_size '] = '16'; // (required) text size
$ Config ['wm _ font_color '] = 'ff000000'; // (required) text color, hexadecimal number
$ Config ['wm _ shadow_color '] = 'ff0000'; // Projection Color, hexadecimal number
$ Config ['wm _ shadow_distance '] = '3'; // font and projection distance (in pixels ).
/* Image watermark parameter settings */
/*
$ Config ['wm _ overlay_path '] = 'ptjsite/upload/overlay.png'; // watermark image name and Path
$ Config ['wm _ opacity '] = '50'; // watermark image transparency
$ Config ['wm _ x_transp '] = '4'; // watermark image Channel
$ Config ['wm _ y_transp '] = '4'; // watermark image Channel
*/
$ This-> image_lib-> initialize ($ config );
$ This-> image_lib-> watermark ();
}

// Image Watermark
Function watermark2 (){
$ Config ['image _ library'] = 'gd2'; // (required) set the image library
$ Config ['source _ image'] = 'ptjsite/upload/003.jpg '; // (required) set the name and path of the original image. the path must be a relative or absolute path, but not a URL.
$ Config ['dynamic _ output'] = FALSE; // TRUE dynamic existence (output image directly to the browser), FALSE written to the hard disk
$ Config ['quality'] = '000000'; // set the image quality. Higher quality, larger image files
$ Config ['new _ image'] = 'ptjsite/upload/crop004.gif '; // set the target name/path of the image.

$ Config ['wm _ type'] = 'overlay '; // (required) set the watermark processing type (text, overlay) to be used)
$ Config ['wm _ padding '] = '5'; // relative position of the image (in pixels)
$ Config ['wm _ vrt_alignment '] = 'middle'; // top, middle, bottom
$ Config ['wm _ hor_alignment '] = 'center'; // left, center, right
$ Config ['wm _ vrt_offset '] = '0'; // specify a vertical offset (in pixels)
$ Config ['wm _ hor_offset '] = '0'; // specify a horizontal offset (in pixels)
/* Text watermark parameter settings */
/*
$ Config ['wm _ text'] = 'copyright 2008-John Doe '; // (required) watermark text content
$ Config ['wm _ font_path'] = 'ptj _ system/fonts/type-ra.ttf '; // font name and Path
$ Config ['wm _ font_size '] = '16'; // (required) text size
$ Config ['wm _ font_color '] = 'ff000000'; // (required) text color, hexadecimal number
$ Config ['wm _ shadow_color '] = 'ff0000'; // Projection Color, hexadecimal number
$ Config ['wm _ shadow_distance '] = '3'; // font and projection distance (in pixels ).
*/

/* Image watermark parameter settings */
$ Config ['wm _ overlay_path '] = 'ptjsite/upload/overlay.png'; // watermark image name and Path
$ Config ['wm _ opacity '] = '50'; // watermark image transparency
$ Config ['wm _ x_transp '] = '4'; // watermark image Channel
$ Config ['wm _ y_transp '] = '4'; // watermark image Channel

$ This-> image_lib-> initialize ($ config );
$ This-> image_lib-> watermark ();
}
}
?>

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.