Created
January 28, 2011 06:55
-
-
Save brandoncordell/799936 to your computer and use it in GitHub Desktop.
dZero Image Lib - CodeIgniter Library
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php if (!defined('BASEPATH')) exit('No direct script access allowed'); | |
/** | |
* dZero image library | |
* | |
* @package dZero Image Library | |
* @category Image Manipulation | |
* @author Daniel Nolan ([email protected]) & Brandon Cordell ([email protected]) | |
* @copyright Copyright (c) 2009 dZero Web Design & Development. | |
* @link http://dzerodesign.com | |
* @version 1.0 | |
* | |
*/ | |
class Dzero_image_lib { | |
/** | |
* Dzero_image_lib constructor | |
* | |
* @access private | |
*/ | |
function Dzero_image_lib() | |
{ | |
// get instance of CI super global | |
$this->CI =& get_instance(); | |
} | |
/** | |
* Get the filetype | |
* | |
* @access public | |
* @param resource | |
* @return string | |
*/ | |
function get_filetype($image) | |
{ | |
} | |
function process_image($image) | |
{ | |
// lets get the file name without extension | |
$name_arr = explode('.', $image); | |
$image_name = $name_arr[0]; | |
$image_ext = $name_arr[1]; | |
if(!$this->grayscale($image, $name_arr[0])) | |
{ | |
echo 'couldn\'t gray'; | |
return FALSE; | |
} | |
if(!$this->mirror($image, $name_arr[0])) | |
{ | |
echo 'couldn\'t mirror'; | |
return FALSE; | |
} | |
if(!$this->combine($image, $name_arr[0])) | |
{ echo 'couldn\'t combine'; | |
return FALSE; | |
} | |
return TRUE; | |
} | |
/** | |
* Grayscale image | |
* | |
* @access public | |
* @param string | |
*/ | |
function grayscale($image, $filename) | |
{ | |
$new = imagecreatefromjpeg($image); | |
// apply the grayscale filter to the image | |
imagefilter($new, IMG_FILTER_GRAYSCALE); | |
// set $filename | |
$filename = $filename."_grayscale.jpg"; | |
// Create new *filtered* image | |
if(!imagejpeg($new, $filename, 100)) | |
return FALSE; | |
// Free up resources | |
imagedestroy($new); | |
return TRUE; | |
} | |
/** | |
* Mirror image | |
* | |
* @access public | |
* @param string | |
*/ | |
function mirror($image, $filename) | |
{ | |
$image = imagecreatefromjpeg($image); | |
// get dimensions from original image | |
$width = imagesx($image); | |
$height = imagesy($image); | |
// create new image resource with same dimensions as original | |
$new = imagecreatetruecolor($width, $height); | |
// flip image while copying | |
for($i = 0; $i < $width; $i++) { | |
imagecopy($new, $image, ($width - $i - 1), 0, $i, 0, 1, $height); | |
} | |
// set $filename | |
$filename = $filename."_mirror.jpg"; | |
// create jpg from true color image resource | |
if(!imagejpeg($new, $filename, 100)) | |
return FALSE; | |
// free up memory | |
imagedestroy($new); | |
return TRUE; | |
} | |
function combine($image, $filename) | |
{ | |
$image = imagecreatefromjpeg($image); | |
imagefilter($image, IMG_FILTER_GRAYSCALE); | |
// get dimensions from original image | |
$width = imagesx($image); | |
$height = imagesy($image); | |
// create new image resource with same dimensions as original | |
$new = imagecreatetruecolor($width, $height); | |
// flip image while copying | |
for($i = 0; $i < $width; $i++) { | |
imagecopy($new, $image, ($width - $i - 1), 0, $i, 0, 1, $height); | |
} | |
// set $filename | |
$filename = $filename."_mirror_gray.jpg"; | |
// create jpg from true color image resource | |
if(!imagejpeg($new, $filename, 100)) | |
return FALSE; | |
// free up memory | |
imagedestroy($new); | |
return TRUE; | |
} | |
} | |
/* End of file dzero_image_lib.php */ | |
/* Location: ./application/libraries/dzero_image_lib.php */ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment