BLOB image display |
[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; }
[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.
[eluser]AlexJ[/eluser]
Set your headers with $this->output->set_header() before outputting the image
[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.
[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" /> 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') Code: $this->output->set_header('etc') Any help??would be appreciated Thanks in advance..
[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');
[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..
[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...ne-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="" />
[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..
[eluser]AlexJ[/eluser]
Please google these questions: http://lmgtfy.com/?q=greek+urls |
Welcome Guest, Not a member yet? Register Sign In |