diff options
author | Andrew <browner12@gmail.com> | 2014-02-11 09:55:48 +0100 |
---|---|---|
committer | Andrew <browner12@gmail.com> | 2014-02-11 09:55:48 +0100 |
commit | b6d8b962e44202a74c9b9321a4a53f61a753fccf (patch) | |
tree | 2d3c533a55964a0d124f7cd6bb1d3d98c7b84056 /user_guide_src/source/libraries/image_lib.rst | |
parent | 41713aaa665189dd0a191c333c73c4a7b9f37c78 (diff) | |
parent | 29e12641a1bb952f493462db6757ae12c7da1f2c (diff) |
Merge branch 'develop' into patch-1
Conflicts:
system/libraries/Calendar.php
Diffstat (limited to 'user_guide_src/source/libraries/image_lib.rst')
-rw-r--r-- | user_guide_src/source/libraries/image_lib.rst | 317 |
1 files changed, 182 insertions, 135 deletions
diff --git a/user_guide_src/source/libraries/image_lib.rst b/user_guide_src/source/libraries/image_lib.rst index dcdccbd92..16acf090b 100644 --- a/user_guide_src/source/libraries/image_lib.rst +++ b/user_guide_src/source/libraries/image_lib.rst @@ -19,6 +19,13 @@ ImageMagick order for the script to calculate the image properties. The image processing, however, will be performed with the library you specify. +.. contents:: + :local: + +.. raw:: html + + <div class="custom-index container"></div> + ********************** Initializing the Class ********************** @@ -29,7 +36,7 @@ in your controller using the $this->load->library function:: $this->load->library('image_lib'); Once the library is loaded it will be ready for use. The image library -object you will use to call all functions is: $this->image_lib +object you will use to call all functions is: ``$this->image_lib`` Processing an Image =================== @@ -67,18 +74,17 @@ ratio. The thumbnail will be called *mypic_thumb.jpg* while processing images you may need to limit their maximum size, and/or adjust PHP memory limits. -Processing Functions -==================== +Processing Methods +================== -There are four available processing functions: +There are four available processing methods: - $this->image_lib->resize() - $this->image_lib->crop() - $this->image_lib->rotate() - $this->image_lib->watermark() -- $this->image_lib->clear() -These functions return boolean TRUE upon success and FALSE for failure. +These methods return boolean TRUE upon success and FALSE for failure. If they fail you can retrieve the error message using this function:: echo $this->image_lib->display_errors(); @@ -88,7 +94,7 @@ error upon failure, like this:: if ( ! $this->image_lib->resize()) { - echo $this->image_lib->display_errors(); + echo $this->image_lib->display_errors(); } .. note:: You can optionally specify the HTML formatting to be applied to @@ -97,6 +103,8 @@ error upon failure, like this:: $this->image_lib->display_errors('<p>', '</p>'); +.. _processing-preferences: + Preferences =========== @@ -146,7 +154,7 @@ Preference Default Value Options pixels. If the source image size does not allow perfect resizing to those dimensions, this setting determines which axis should be used as the hard value. "auto" sets the axis automatically based on whether the - image is taller then wider, or vice versa. + image is taller than wider, or vice versa. **rotation_angle** None 90, 180, 270, vrt, hor Specifies the angle of rotation when rotating images. Note that PHP X rotates counter-clockwise, so a 90 degree rotation to the right must be specified as 270. @@ -162,134 +170,10 @@ Setting preferences in a config file If you prefer not to set preferences using the above method, you can instead put them into a config file. Simply create a new file called image_lib.php, add the $config array in that file. Then save the file -in: config/image_lib.php and it will be used automatically. You will -NOT need to use the $this->image_lib->initialize function if you save +in *config/image_lib.php* and it will be used automatically. You will +NOT need to use the ``$this->image_lib->initialize()`` method if you save your preferences in a config file. -$this->image_lib->resize() -=========================== - -The image resizing function lets you resize the original image, create a -copy (with or without resizing), or create a thumbnail image. - -For practical purposes there is no difference between creating a copy -and creating a thumbnail except a thumb will have the thumbnail marker -as part of the name (ie, mypic_thumb.jpg). - -All preferences listed in the table above are available for this -function except these three: rotation_angle, x_axis, and y_axis. - -Creating a Thumbnail --------------------- - -The resizing function will create a thumbnail file (and preserve the -original) if you set this preference to TRUE:: - - $config['create_thumb'] = TRUE; - -This single preference determines whether a thumbnail is created or not. - -Creating a Copy ---------------- - -The resizing function will create a copy of the image file (and preserve -the original) if you set a path and/or a new filename using this -preference:: - - $config['new_image'] = '/path/to/new_image.jpg'; - -Notes regarding this preference: - -- If only the new image name is specified it will be placed in the same - folder as the original -- If only the path is specified, the new image will be placed in the - destination with the same name as the original. -- If both the path and image name are specified it will placed in its - own destination and given the new name. - -Resizing the Original Image ---------------------------- - -If neither of the two preferences listed above (create_thumb, and -new_image) are used, the resizing function will instead target the -original image for processing. - -$this->image_lib->crop() -========================= - -The cropping function works nearly identically to the resizing function -except it requires that you set preferences for the X and Y axis (in -pixels) specifying where to crop, like this:: - - $config['x_axis'] = '100'; - $config['y_axis'] = '40'; - -All preferences listed in the table above are available for this -function except these: rotation_angle, create_thumb, new_image. - -Here's an example showing how you might crop an image:: - - $config['image_library'] = 'imagemagick'; - $config['library_path'] = '/usr/X11R6/bin/'; - $config['source_image'] = '/path/to/image/mypic.jpg'; - $config['x_axis'] = '100'; - $config['y_axis'] = '60'; - - $this->image_lib->initialize($config); - - if ( ! $this->image_lib->crop()) - { - echo $this->image_lib->display_errors(); - } - -.. note:: Without a visual interface it is difficult to crop images, so this - function is not very useful unless you intend to build such an - interface. That's exactly what we did using for the photo gallery module - in ExpressionEngine, the CMS we develop. We added a JavaScript UI that - lets the cropping area be selected. - -$this->image_lib->rotate() -=========================== - -The image rotation function requires that the angle of rotation be set -via its preference:: - - $config['rotation_angle'] = '90'; - -There are 5 rotation options: - -#. 90 - rotates counter-clockwise by 90 degrees. -#. 180 - rotates counter-clockwise by 180 degrees. -#. 270 - rotates counter-clockwise by 270 degrees. -#. hor - flips the image horizontally. -#. vrt - flips the image vertically. - -Here's an example showing how you might rotate an image:: - - $config['image_library'] = 'netpbm'; - $config['library_path'] = '/usr/bin/'; - $config['source_image'] = '/path/to/image/mypic.jpg'; - $config['rotation_angle'] = 'hor'; - - $this->image_lib->initialize($config); - - if ( ! $this->image_lib->rotate()) - { - echo $this->image_lib->display_errors(); - } - -$this->image_lib->clear() -========================== - -The clear function resets all of the values used when processing an -image. You will want to call this if you are processing images in a -loop. - -:: - - $this->image_lib->clear(); - - ****************** Image Watermarking ****************** @@ -310,10 +194,12 @@ There are two types of watermarking that you can use: image (usually a transparent PNG or GIF) containing your watermark over the source image. +.. _watermarking: + Watermarking an Image ===================== -Just as with the other functions (resizing, cropping, and rotating) the +Just as with the other methods (resizing, cropping, and rotating) the general process for watermarking involves setting the preferences corresponding to the action you intend to perform, then calling the watermark function. Here is an example:: @@ -423,3 +309,164 @@ Preference Default Value Options Description coordinate to a pixel representative of the color you want to be transparent. ======================= =================== =================== ========================================================================== + +*************** +Class Reference +*************** + +.. class:: CI_Image_lib + + .. method:: initialize([$props = array()]) + + :param array $props: Image processing preferences + :returns: TRUE on success, FALSE in case of invalid settings + :rtype: bool + + Initializes the class for processing an image. + + .. method:: resize() + + :returns: TRUE on success, FALSE on failure + :rtype: bool + + The image resizing method lets you resize the original image, create a + copy (with or without resizing), or create a thumbnail image. + + For practical purposes there is no difference between creating a copy + and creating a thumbnail except a thumb will have the thumbnail marker + as part of the name (i.e. mypic_thumb.jpg). + + All preferences listed in the :ref:`processing-preferences` table are available for this + method except these three: *rotation_angle*, *x_axis* and *y_axis*. + + **Creating a Thumbnail** + + The resizing method will create a thumbnail file (and preserve the + original) if you set this preference to TRUE:: + + $config['create_thumb'] = TRUE; + + This single preference determines whether a thumbnail is created or not. + + **Creating a Copy** + + The resizing method will create a copy of the image file (and preserve + the original) if you set a path and/or a new filename using this + preference:: + + $config['new_image'] = '/path/to/new_image.jpg'; + + Notes regarding this preference: + + - If only the new image name is specified it will be placed in the same + folder as the original + - If only the path is specified, the new image will be placed in the + destination with the same name as the original. + - If both the path and image name are specified it will placed in its + own destination and given the new name. + + **Resizing the Original Image** + + If neither of the two preferences listed above (create_thumb, and + new_image) are used, the resizing method will instead target the + original image for processing. + + .. method:: crop() + + :returns: TRUE on success, FALSE on failure + :rtype: bool + + The cropping method works nearly identically to the resizing function + except it requires that you set preferences for the X and Y axis (in + pixels) specifying where to crop, like this:: + + $config['x_axis'] = 100; + $config['y_axis'] = 40; + + All preferences listed in the :ref:`processing-preferences` table are available for this + method except these: *rotation_angle*, *create_thumb* and *new_image*. + + Here's an example showing how you might crop an image:: + + $config['image_library'] = 'imagemagick'; + $config['library_path'] = '/usr/X11R6/bin/'; + $config['source_image'] = '/path/to/image/mypic.jpg'; + $config['x_axis'] = 100; + $config['y_axis'] = 60; + + $this->image_lib->initialize($config); + + if ( ! $this->image_lib->crop()) + { + echo $this->image_lib->display_errors(); + } + + .. note:: Without a visual interface it is difficult to crop images, so this + method is not very useful unless you intend to build such an + interface. That's exactly what we did using for the photo gallery module + in ExpressionEngine, the CMS we develop. We added a JavaScript UI that + lets the cropping area be selected. + + .. method:: rotate() + + :returns: TRUE on success, FALSE on failure + :rtype: bool + + The image rotation method requires that the angle of rotation be set + via its preference:: + + $config['rotation_angle'] = '90'; + + There are 5 rotation options: + + #. 90 - rotates counter-clockwise by 90 degrees. + #. 180 - rotates counter-clockwise by 180 degrees. + #. 270 - rotates counter-clockwise by 270 degrees. + #. hor - flips the image horizontally. + #. vrt - flips the image vertically. + + Here's an example showing how you might rotate an image:: + + $config['image_library'] = 'netpbm'; + $config['library_path'] = '/usr/bin/'; + $config['source_image'] = '/path/to/image/mypic.jpg'; + $config['rotation_angle'] = 'hor'; + + $this->image_lib->initialize($config); + + if ( ! $this->image_lib->rotate()) + { + echo $this->image_lib->display_errors(); + } + + .. method:: watermark() + + :returns: TRUE on success, FALSE on failure + :rtype: bool + + Creates a watermark over an image, please refer to the :ref:`watermarking` + section for more info. + + .. method:: clear() + + :rtype: void + + The clear method resets all of the values used when processing an + image. You will want to call this if you are processing images in a + loop. + + :: + + $this->image_lib->clear(); + + .. method:: display_errors([$open = '<p>[, $close = '</p>']]) + + :param string $open: Error message opening tag + :param string $close: Error message closing tag + :returns: Error messages + :rtype: string + + Returns all detected errors formatted as a string. + :: + + echo $this->image_lib->diplay_errors();
\ No newline at end of file |