jordz Posted April 4, 2010 Share Posted April 4, 2010 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($newimg, 255, 255, 255); for ($i = 0; $i < $height; $i++) { for ($j = 0; $j < $width; $j++) { $rgb = imagecolorat($img, $j, $i); $r = ($rgb >> 16) & 0xFF; $g = ($rgb >> & 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($newimg, NULL, 100); 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'); } } ?> 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 Link to comment https://forums.phpfreaks.com/topic/197551-using-a-class-that-returns-an-image-how-to-display-the-image-code-igniter/ Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.