Deep analytic _php technique of codeigniter image processing class

Source: Internet
Author: User
Tags codeigniter
image.php
Copy Code code as follows:

<?php
Class Image extends Controller {
function Image ()
{
Parent::controller ();
$this->load->library (' image_lib ');
}

Thumbnail image
function index () {
Echo ' * Adjust image size <br>
* Create thumbnails <br>
* Image Cutting <br>
* Image Rotation <br>
* Add image Watermark <br>
';
}
Thumbnail image
function Resize () {
/*
Attention
Adjusts the size of the original image when $config[' create_thumb ' is equal to false and $config[' New_image ' is not specified
When $config[' Create_thumb ' equals True and $config[' New_image ' is not specified, the generated file name is (original name _thumb. extension)
Generates a value of $config[' New_image ' when $config[' create_thumb ' is equal to false and $config[' New_image '] specified
When $config[' Create_thumb ' equals True and $config[' New_image ' is specified, the generated file name is (original name _thumb. extension)
*/
$config [' image_library '] = ' gd2 ';//(must) Set Image Library
$config [' source_image '] = ' ptjsite/upload/55002.jpg ';//(must) set the name/path of the original image
$config [' dynamic_output '] = false;//Determines whether the new image is to be written to a hard disk or a dynamic existence
$config [' quality '] = ' 90% ';//Set the quality of the image. The higher the quality, the larger the image file
$config [' new_image '] = ' ptjsite/upload/resize004.gif ';//Set the target name/path of the image.
$config [' width '] = 575;//(must) set the width of the image you want.
$config [' height '] = 350;//(must) set the height of the image you want
$config [' create_thumb '] = true;//let the image processing function produce a preview image (before inserting _thumb into the file name extension)
$config [' thumb_marker '] = ' _thumb ';//Specify the indication of the preview image. It will be inserted before the file name extension. For example, Mypic.jpg will become mypic_thumb.jpg
$config [' maintain_ratio '] = true;//maintenance ratio
$config [' master_dim '] = ' auto ';//auto, width, height specify the main axis
$this->image_lib->initialize ($config);
if (! $this->image_lib->resize ())
{
echo $this->image_lib->display_errors ();
}else{
echo "Successful";
}
}
Image cropping
function crop () {
$config [' image_library '] = ' gd2 ';//Set Image Library
$config [' source_image '] = ' ptjsite/upload/004.gif ';//(must) set the name/path of the original image
$config [' dynamic_output '] = false;//Determines whether the new image is to be written to a hard disk or a dynamic existence
$config [' quality '] = ' 90% ';//Set the quality of the image. The higher the quality, the larger the image file
$config [' new_image '] = ' ptjsite/upload/crop004.gif ';//(must) set the target name/path of the image.

$config [' width '] = 75;//(must) set the width of the image you want.
$config [' height '] = 50;//(must) set the height of the image you want
$config [' maintain_ratio '] = true;//maintenance ratio
$config [' x_axis '] = ' 30 ';//(must) the pixel value from the left
$config [' y_axis '] = ' 40 ';//(must) the pixel value taken from the head

$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 ';//(must) Set Image Library
$config [' source_image '] = ' ptjsite/upload/001.jpg ';//(must) set the name/path of the original image
$config [' dynamic_output '] = false;//Determines whether the new image is to be written to a hard disk or a dynamic existence
$config [' quality '] = ' 90% ';//Set the quality of the image. The higher the quality, the larger the image file
$config [' new_image '] = ' ptjsite/upload/rotate001.jpg ';//Set the target name/path of the image
$config [' rotation_angle '] = ' VRT ';//There are 5 rotation options counterclockwise 90 180 270 degrees VRT vertical flip hor flip sideways
$this->image_lib->initialize ($config);

if (! $this->image_lib->rotate ())
{
echo $this->image_lib->display_errors ();
}
}

Text watermark
function watermark () {
$config [' image_library '] = ' gd2 ';//(must) Set Image Library
$config [' source_image '] = ' ptjsite/upload/003.jpg ';//(must) 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 presence (output image directly to browser), FALSE to hard disk
$config [' quality '] = ' 90% ';//Set the quality of the image. The higher the quality, the larger the image file
$config [' new_image '] = ' ptjsite/upload/crop004.gif ';//Set the target name/path of the image.

$config [' wm_type '] = ' overlay ';//(must) set the type of watermark processing you want to use (text, overlay)
$config [' wm_padding '] = ' 5 ';//image relative position (per pixel)
$config [' wm_vrt_alignment '] = ' middle ';//vertical axis position top, middle, bottom
$config [' wm_hor_alignment '] = ' center ';//horizontal axis position 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 Setting * *
$config [' wm_text '] = ' Copyright 2008-john Doe ';//(must) the text content of the watermark
$config [' wm_font_path '] = ' ptj_system/fonts/type-ra.ttf ';//font name and path
$config [' wm_font_size '] = ' 16 ';//(must) text size
$config [' wm_font_color '] = ' FF0000 ';//(must) text color, hexadecimal number
$config [' wm_shadow_color '] = ' FF0000 ';//projection color, hexadecimal number
$config [' wm_shadow_distance '] = ' 3 ';//font and projection distance (per pixel).
/* Image watermark parameter Setting * *
/*
$config [' wm_overlay_path '] = ' ptjsite/upload/overlay.png ';//watermark image Name and path
$config [' wm_opacity '] = ' 50 ';//transparency of watermark image
$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 ';//(must) Set Image Library
$config [' source_image '] = ' ptjsite/upload/003.jpg ';//(must) 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 presence (output image directly to browser), FALSE to hard disk
$config [' quality '] = ' 90% ';//Set the quality of the image. The higher the quality, the larger the image file
$config [' new_image '] = ' ptjsite/upload/crop004.gif ';//Set the target name/path of the image.

$config [' wm_type '] = ' overlay ';//(must) set the type of watermark processing you want to use (text, overlay)
$config [' wm_padding '] = ' 5 ';//image relative position (per pixel)
$config [' wm_vrt_alignment '] = ' middle ';//vertical axis position top, middle, bottom
$config [' wm_hor_alignment '] = ' center ';//horizontal axis position 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 Setting * *
/*
$config [' wm_text '] = ' Copyright 2008-john Doe ';//(must) the text content of the watermark
$config [' wm_font_path '] = ' ptj_system/fonts/type-ra.ttf ';//font name and path
$config [' wm_font_size '] = ' 16 ';//(must) text size
$config [' wm_font_color '] = ' FF0000 ';//(must) text color, hexadecimal number
$config [' wm_shadow_color '] = ' FF0000 ';//projection color, hexadecimal number
$config [' wm_shadow_distance '] = ' 3 ';//font and projection distance (per pixel).
*/

/* Image watermark parameter Setting * *
$config [' wm_overlay_path '] = ' ptjsite/upload/overlay.png ';//watermark image Name and path
$config [' wm_opacity '] = ' 50 ';//transparency of watermark image
$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.