CodeIgniter Forums
BLOB image display - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20)
+--- Forum: Archived Libraries & Helpers (https://forum.codeigniter.com/forumdisplay.php?fid=22)
+--- Thread: BLOB image display (/showthread.php?tid=38023)

Pages: 1 2


BLOB image display - El Forum - 01-27-2011

[eluser]Unknown[/eluser]
Created a helper function for to view the blob image in codeigniter with user defined height and width, but it only showing the binary data not the image.Its working fine with core PHP
anybody help?Thanks in advance

This is the code

function getImage($toWidth,$toHeight,$image)
{
$blob_binary = $image['image_data'];

$width = $image['image_width'];
$height = $image['image_height'];
$xscale = $width/$toWidth;
$yscale = $height/$toHeight;

// Recalculate new size with default ratio
if ($yscale>$xscale){
$new_width = round($width * (1/$yscale));
$new_height = round($height * (1/$yscale));
}
else {
$new_width = round($width * (1/$xscale));
$new_height = round($height * (1/$xscale));
}

$im = imagecreatefromstring($blob_binary);
$new_image = imagecreatetruecolor($new_width, $new_height);
$x = imagesx($im);
$y = imagesy($im);
imagecopyresampled($new_image, $im, 0, 0, 0, 0, $new_width, $new_height, $x, $y);
imagedestroy($im);
imagejpeg($new_image, null, 85);

header("Content-type: ".$image['image_type']);
echo $new_image;
}


BLOB image display - El Forum - 01-28-2011

[eluser]CroNiX[/eluser]
looks fine I think except the very end.
imagejpeg outputs to the browser directly (since you used NULL as 2nd parameter), so put your header just above that. echo $new_image; would be unnecessary.


BLOB image display - El Forum - 01-30-2011

[eluser]AlexJ[/eluser]
Set your headers with $this->output->set_header() before outputting the image


BLOB image display - El Forum - 05-22-2011

[eluser]Stefanos Ka[/eluser]
Hi,
i have a page where i want to show an image retrieved from BLOB field.


i have a problem with the header function of php..I don't know if ci makes matter but when i use the Header('Content-type: image/jpg') nothing get loaded. I get a white page.


BLOB image display - El Forum - 05-22-2011

[eluser]Stefanos Ka[/eluser]
Hi,
i have a page where i want to show an image retrieved from a BLOB field.
i'm using a "template.php" page which is the main page and there i send as an argument which view file to load.
At the top of the "template.php" i have the
Code:
<meta http-equiv="content-type" content="text/html;charset=utf-8" />
for showing greek characters.
Everything works fine except the view file which shows the image. Actually, i don't know if ci makes matter but when i use the
Code:
Header('Content-type: image/jpg')
function or
Code:
$this->output->set_header('etc')
(so to be able to print the picture data from db)..nothing gets loaded. I get a white page.

Any help??would be appreciated
Thanks in advance..


BLOB image display - El Forum - 05-22-2011

[eluser]AlexJ[/eluser]
You should not echo out the output, but use $this->output->set_output() instead, so something like this:

Code:
$this->output->set_header('Content-type: image/jpg');
$this->output->set_output($image_data);



BLOB image display - El Forum - 05-22-2011

[eluser]Stefanos Ka[/eluser]
Thanks AlexJ. It works. The image is shown BUT i'm not getting the rest of the data shown.. :/
Which are simple text..
I think the problem is in the "set_header" specification. Is there a way to set both "text/html" and "image/jpg" ??

Thanks in advance..


BLOB image display - El Forum - 05-22-2011

[eluser]AlexJ[/eluser]
You cannot mix two mimetypes, so what you want isnt possible unless you use a data url, but they are poorly supported: http://www.websiteoptimization.com/speed/tweak/inline-images/

Just make a image controller, and make that controller show the images, so for instance use:

image/view/{image_id} to show the image, and then use a img tag in the html:

<img src="index.php/view/{image_id}" alt="" />


BLOB image display - El Forum - 05-22-2011

[eluser]Stefanos Ka[/eluser]
Thanks again AlexJ. I will probably search for an alternative solution. Btw is it possible to load an image file using the <img> tag but the filename will be in greek? I test it and it fails..


BLOB image display - El Forum - 05-22-2011

[eluser]AlexJ[/eluser]
Please google these questions: http://lmgtfy.com/?q=greek+urls