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.'">';
Related
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 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 :
I am trying to upload image to php web service and store it in MS SQL database. My post data is in json format which has base64 encoded image data.
Base 64 encode and insert sample
$base=base64_encode(file_get_contents("C:\sample\images.jpg"));
$CommandText = "INSERT INTO [M_IMAGES] ([IMAGE_DATA]) VALUES(?) " ;
$ImageStream = imagecreatefromstring(base64_decode($this->imageData));
$RowsAffected = (int)$objDBManager->Exe*emphasized text*cuteNonQuery($CommandText,array(array($ImageStream,
SQLSRV_PARAM_IN,
SQLSRV_PHPTYPE_STREAM(SQLSRV_ENC_BINARY),
SQLSRV_SQLTYPE_VARBINARY('max'))));
Here $this->imageData contanins base64 encoded image data and IMAGE_DATA datatype is image. I am able to upload and retrieve image successfully in normal upload
Normal upload
$ImagePath = $_FILES[$ImageCtrlName]['tmp_name'];
$ImageStream = fopen($ImagePath, "r");
$RowsAffected = (int)$objDBManager->ExecuteNonQuery($CommandText,
array(array(&$ImageStream,
SQLSRV_PARAM_IN,
SQLSRV_PHPTYPE_STREAM(SQLSRV_ENC_BINARY),
SQLSRV_SQLTYPE_VARBINARY('max'))));
fclose($ImageStream);
I am getting error sqlsrv_query(): supplied resource is not a valid stream resource
Can anyone point out what is wrong here. Or is there a better way to do it. Help me as I am new to PHP.
The best solution is to save in the DB only the url of the image and save the image in your server.
When you want to print it you only have to search the url in the DB.
Trying to save the image in a DB is a wrong solution.
From what I can understand from your question, your problem stems from trying to store the image on to MSSQL as it's binary form, which is not allowed. What I can do, is advice you to store the image in it's base64 form, which is a string of alphanumeric characters. There is no need to try and store the image as an image as the base64 encoded image, is usually serve-able directly to the client.
TL;DR Just store the image as base64.
Source image
http://i.imgur.com/TbffELG.jpg
This is a vertical image, but when I upload it to server, server got the size width="3264" height="1836", and my resize and crop function will be wrong
there is the demo site http://demo.chan15.info/im/
PHP code
<?php
$file = $_FILES['file'];
$tmp = $file['tmp_name'];
$imageInfo = getimagesize($tmp);
echo '<pre>'; var_dump($imageInfo); echo '</pre>';
If the photo was taken on a mobile phone it can apply meta data regarding the orientation of the device at the time, which is used to infer the correct way to display the image. Not all decoders support the meta data, and will display the image incorrectly. In this case your image will probably display on its side.
You either need an image library capable of dealing with this meta data, or you can transform the image and/or remove the meta data. Apologies, but I can't suggest a suitable image library.
I had the same Problem. As HenryTK said the central problem is that the orientation of the picture is stored in the EXIF data (used by modern cameras and smartphones) while the width and length information indicate a landscape picture.
My solution is to open the picture with GIMP. GIMP shows the following modal dialog:
Now you only have to click the rotate button and save the picture.
It's not the best solution. If somebody has a script or something please tell me.
First I want to tell you guys I'm a beginner to this. I'm developing a website, I want to allow users to upload any size of images in a variety of formats (GIF,JPEG,PNG).
And I want to re size the image and convert the image format into PNG. Im not inserting the image into database as BLOBs.
this is my code, But I'm uploading the image directly here, How to re size and convert to PNG:
$myImage = $_FILES['imgCover']['name'];
$response = mysql_query("INSERT INTO gallery (imagename) VALUE ('$myImage')");
if($response === true)
{
move_uploaded_file($_FILES['imgCover']['tmp_name'],"images/gallery/".$_FILES['imgCover']['name'])
}
Please help me.
Something like http://salman-w.blogspot.com/2008/10/resize-images-using-phpgd-library.html?
Just use png where its says jpeg, like
imagejpeg
etc.