1 <?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
4 * An image processing library initially intended for creating thumbnails.
7 * @author Simon Jarvis, Călin-Andrei Burloiu
8 * @copyright 2006 Simon Jarvis, 2011 Călin-Andrei Burloiu
16 function load($filename) {
17 $image_info = getimagesize($filename);
18 $this->image_type = $image_info[2];
19 if( $this->image_type == IMAGETYPE_JPEG ) {
20 $this->image = imagecreatefromjpeg($filename);
21 } elseif( $this->image_type == IMAGETYPE_GIF ) {
22 $this->image = imagecreatefromgif($filename);
23 } elseif( $this->image_type == IMAGETYPE_PNG ) {
24 $this->image = imagecreatefrompng($filename);
27 function save($filename, $image_type=IMAGETYPE_JPEG, $compression=60, $permissions=null) {
28 if( $image_type == IMAGETYPE_JPEG ) {
29 imagejpeg($this->image,$filename,$compression);
30 } elseif( $image_type == IMAGETYPE_GIF ) {
31 imagegif($this->image,$filename);
32 } elseif( $image_type == IMAGETYPE_PNG ) {
33 imagepng($this->image,$filename);
35 if( $permissions != null) {
36 chmod($filename,$permissions);
39 function output($image_type=IMAGETYPE_JPEG) {
40 if( $image_type == IMAGETYPE_JPEG ) {
41 imagejpeg($this->image);
42 } elseif( $image_type == IMAGETYPE_GIF ) {
43 imagegif($this->image);
44 } elseif( $image_type == IMAGETYPE_PNG ) {
45 imagepng($this->image);
48 function saveThumbnail($filename, $width, $height)
50 $ratio = $this->getWidth() / $this->getHeight();
51 $thumbRatio = $width / $height;
53 if($ratio < $thumbRatio)
54 $this->resizeToHeight($height);
56 $this->resizeToWidth($width);
58 $this->save($filename);
61 return imagesx($this->image);
63 function getHeight() {
64 return imagesy($this->image);
66 function resizeToHeight($height) {
67 $ratio = $height / $this->getHeight();
68 $width = $this->getWidth() * $ratio;
69 $this->resize($width,$height);
71 function resizeToWidth($width) {
72 $ratio = $width / $this->getWidth();
73 $height = $this->getheight() * $ratio;
74 $this->resize($width,$height);
76 function scale($scale) {
77 $width = $this->getWidth() * $scale/100;
78 $height = $this->getheight() * $scale/100;
79 $this->resize($width,$height);
81 function resize($width,$height) {
82 $new_image = imagecreatetruecolor($width, $height);
83 imagecopyresampled($new_image, $this->image, 0, 0, 0, 0, $width, $height, $this->getWidth(), $this->getHeight());
84 $this->image = $new_image;
89 /* End of file Singleton_db.php */
90 /* Location: ./application/libraries/Singleton_db.php */