Author Topic: Using a class that returns an image, how to display the image? Code Igniter  (Read 372 times)

0 Members and 1 Guest are viewing this topic.

Offline jordzTopic starter

  • Irregular
  • Posts: 36
    • View Profile
Hey Everyone,

I'm new to code igniter literally just downloaded it and messing about with it. I know I'm diving head first into the deep end here but all I want to test out is the inclusion of external classes, like a photo manipulation class.

For example currently I have a class that Equalises a photo and manipulates it, it does it's business here:
Class Equalise{
        
// Main output function which reads the file and runs it through histogram equalization for the various color channels.
        
function outputimage($filename) {

                
$reds = array();
                
$blues = array();
                
$greens = array();
                
                
$freqr = array();
                
$freqb = array();
                
$freqg = array();
                
                
$info getimagesize($filename);
                
                
$width $info[0];
                
$height $info[1];
                
$totalpixels $width $height;
                
                
                
$img imagecreatefromjpeg($filename);
                
                if (
$img) {
                        
Equalise::buildHistograms($img$width$height$reds$greens$blues);
                        
Equalise::buildFrequencies($reds$greens$blues$freqr$freqg$freqb);
                }
                
                
$alpha = (float)(255.0 / (float)$totalpixels);
                
$newimg = @imagecreatetruecolor($width$height);
                
$color imagecolorallocate($newimg255255255);
                
                for (
$i 0$i $height$i++) {
                        for (
$j 0$j $width$j++) {
                                
$rgb imagecolorat($img$j$i);
                                
$r = ($rgb >> 16) & 0xFF;
                                
$g = ($rgb >> 8) & 0xFF;
                                
$b $rgb 0xFF;
                                
                                
$adjR = (int)((float)$freqr[$r] * $alpha);
                                
$adjG = (int)((float)$freqg[$g] * $alpha);
                                
$adjB = (int)((float)$freqb[$b] * $alpha);
                                
                                
$color imagecolorallocate($newimg$adjR$adjG$adjB); 
                                
imagesetpixel($newimg$j$i$color);
                        }
                }
                
// This is where the Image comes out.
                
header('Content-Type: image/jpg');
                
imagejpeg($newimgNULL100);
                
imagedestroy($newimg);
        }


It returns the image then destroys it but after it's been loaded into the browser.

I've been messing and added it into the application/libraries, as it said in the CI documentation, and in my Test controller added this code:


<?php
class Test extends Controller{

 function 
index(){
 
header('Content-Type: image/jpg');
 
$this->load->library('Equalise');
 
$this->equalise->outputimage($_SERVER['DOCUMENT_ROOT']'/3.jpg');
 
 }



}

?&
gt;


This takes 3.jpg and runs it through the class. But I just does't seem to work I can't get an image to come out at all.
Anyone have any idea's?
Thanks,

Jordan
« Last Edit: April 04, 2010, 12:40:53 PM by jordz »