I want to display image from blob mysql data, but image not display, here the code :
$data = $this->Api_m->getData("calon", 'id_calon', $id)->result()[0]->gambar_calon;
header('Content-Type: image/png');
imagepng($data);
image type is png, and when i download from phpmyadmin is work. and because I want to show image in android so i cant use base64 image like this way:
src='data:image/jpeg;base64
Browser screenshot :
Related
I have a image in binary format stored in my database (SQL Server). I export these images by a backend procedure in .PNG format. The image exported successfully but when I am displaying the image in my webpage, it does not work. But if I open the image in Paint and save as .PNG format again, it works. Thank you in advance for your cooperation. Here is my code to display:
$image = 'D:\\myImage.PNG';
$imageData = base64_encode(file_get_contents($image));
echo '<img src="data:image/PNG;base64,'.$imageData.'">';
I have a form in my Android app that send information to php server with an image pick button. I want to resize image before saving on server with php codes :
<?php
move_uploaded_file($_FILES['file']['tmp_name'],'uploads/'.$_FILES['file']
['name']);
$orgfile='uploads/'.$_FILES['file']['name'];
list($width,$height)=getimagesize($orgfile);
$newfile=imagecreatefromjpeg($orgfile);
$thumb='uploads/a/'.$_FILES['file']['name'];
$truecolor=imagecreatetruecolor(600,400);
imagecopyresampled($truecolor,$newfile,0,0,0,0,600,400,$width,$height);
imagejpeg($truecolor,$thumb,100);
unlink($orgfile);
?>
This code just resize jpeg images and another formats (png or gif and even jpg) saved a black image.
It is necessary to mention that name of image file changed to a random number like "32165465423" and I don't know the image format to use "imagecreatefrompng" or "imagecreatefromgif" in my php file.
I want a code like "imagecreatefromall" or another ...
Thanks guys(sorry for bad English)
You will have to detect the type of image, based on that you can run the function. See the one cool php library for reference
https://github.com/eventviva/php-image-resize/blob/master/lib/ImageResize.php#L77
I am creating a PDF with fpdf
I can insert an image such as
$pdf->Image('images/image.jpg',0,20,210,80);
I can insert an image such as
$pdf->Image('http://www.thesearchagents.com/wp-content/uploads/2013/11/Google-Search.jpg',0,20,210,80);
in HTML I can serve an image to my page with
<img src="http://maps.googleapis.com/maps/api/staticmap?center=Berkeley,CA&zoom=14&size=400x400&sensor=false" alt="image" height="200" width="300" />
but if I try
$pdf->Image('http://maps.googleapis.com/maps/api/staticmap?center=Berkeley,CA&zoom=14&size=400x400&sensor=false',0,20,210,80);
I get an error
"FPDF error: Unsupported image type: php"
since it is not the actual image file and is only serving the image I am guessing it does not work with setting the header
header('Content-Type: image/png');
what can I do?
Can I capture the image binary and store it in a variable? to then be passed along?
If so, then my question is:
How do capture the image source from a return of a php file and store it in a variable in php?
$bin = file_get_contents('http://your_image_binary_source_url_here'); //fetch binary source
$local_name = "/tmp/".time().'.png';
file_put_contents($local_name, $bin); //create image locally
$pdf->Image($local_name,0,20,210,80); //add image to pdf
unlink($local_name); //delete local image
i have a website in which when a user uploads a file or document it is stored in database in BLOB datatype.
Also there is a download link which retrives the document from database and lets the user download.
now i want this document to be viewed in a document viewer like google doc viewer,how do i go about doing this ?
if you know the type of the file being downloaded you can use some thing like
Simple example:
$blob = "some data";
header('Content-type: image/jpeg'); // e.g. if a JPEG image
echo $blob;
Lets say I have this data url from Apple:
data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAA0AAAANCAYAAABy6%2BR8AAAAlElEQVR42oWQQRHEIAxF10ElVAISVgo3bCABCUhYCZWAhEpAQpoD6bzJhNnDO0DyyA8fEXkppXyVCpLViDUfyqVIQN9JFMY637hrlCySFauL21E7KVWbAIGx56rnSLqc5KPXSLo3kySalPhTygFhRDtFC09EIsMeZJSGBj7Qveh3OJW89syImiH%2BIO2BOJX0XwA2%2BQEL4pAhSX4aBQAAAABJRU5ErkJggg%3D%3D
That I want to save as a png file.How do I do That?
Rightclicking and 'Save image as' is not working(Why?)
So I thought I should use a PHP script with the 'base64_decode' function:
$img = "iVBORw0KGgoAAAANSUhEUgAAA9QAAAAkCAMAAABfcIIyAAAAGXRFWHRTb2Z0d2FyZQBBZG9iZSBJbWFnZVJlYWR5ccllPAAAAHVQTFRFAAAA%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F%2F%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hlC2R318r2px%2BeQqLpPJDae9P5%2FmrVz491%2FWekBlKy7PXVfn9rb9xXsMD2wdOcAAAAAElFTkSuQmCC";
header("Content-type: image/png");
echo base64_decode($img);
That is giving me back the broken image icon :
How should I solve this problem and save a data url image to a file?
Your code is fine, but your base64 is urlencoded. I urldecoded it for you: iVBORw0KGgoAAAANSUhEUgAAAA0AAAANCAYAAABy6+R8AAAAlElEQVR42oWQQRHEIAxF10ElVAISVgo3bCABCUhYCZWAhEpAQpoD6bzJhNnDO0DyyA8fEXkppXyVCpLViDUfyqVIQN9JFMY637hrlCySFauL21E7KVWbAIGx56rnSLqc5KPXSLo3kySalPhTygFhRDtFC09EIsMeZJSGBj7Qveh3OJW89syImiH+IO2BOJX0XwA2+QEL4pAhSX4aBQAAAABJRU5ErkJggg==
or do it yourself:
base64_decode(urldecode($img));