This question already has an answer here:
Closed 11 years ago.
Possible Duplicate:
Getting exif data from php
I am making a gallery from images in a folder using the following code:
<div id="gallery"><ul>
<?php
foreach (glob("gallery/*") as $filename) {
echo '<li><a href="'.$filename.'" title="">';
echo '<img src="'.$filename.'" alt="" /></a></li>';
}
?>
</ul></div>
In the title filed of a tag I want to print a description from the image file properties. Is there any way?
i made some changes to this code using getimagedata() function...
<div id="gallery"><ul> <?php
foreach (glob("gallery/*.jpg") as $filename) {
$size = getimagesize($filename, $info);
echo '<li><a href="'.$filename.'" title="';
var_dump($info['APP0']);
echo '"><img src="'.$filename.'" alt="" /></a></li>';
}
?></ul></div>
but it gives unreadable output. like this string 'JFIF���d�d��' (length=14)
and also i used exif_read_data() function it show call to undefined function error....
I'm not quite sure, but exif_read_data() should do the job.
It may depend on where the metadata are stored (and of course also on the format of the files: not all image formats allow metadata). Beyond EXIF, you could be interested also in reading about iptcparse. For example images created or manipulated with Adobe PhotoShop could have some metadata you could be interested in as IPTC metadata. See also the IPTC Photo Metadata Standard.
Related
I have a database which contains images saved as BLOBs. I can successfully use the image on a page like so :
<img src="<?php echo 'data:image/jpeg;base64,'.base64_encode($image)?>" alt="Landing" width="150px">
However this requires setting the file extension manually in the actual statement at data:image/jpeg;. The problem is that I have lots of various images in various formats. I want to make sure that the filetype is set properly based on the actual file extension of the specific file for each image. I already have a nested array which contains all the file extensions for those files.
Nonetheless I am having trouble setting the extension dynamically. I've tried simply replacing the '' single quotes with "" to allow me to easily use a variable inside of the statement like so :
<img src="<?php echo "data:image/$images['monitor']['extension'];base64,".base64_encode($image)?>" alt="Landing" width="150px">
This doesn't work because the src tag itself contains double-quotes already I believe. My IDE tells me an error Cannot use '[]' for reading. I've also tried using concatinated single quotes instead :
<img src="<?php echo 'data:image/' . $images['monitor']['extension'] . ';base64,'.base64_encode($image)?>" alt="Monitor" width="150px">
Which also did not work. I was unable to find any solution to this online myself. Is there any way to dynamically set the file extension? Although setting jpeg for each image mostly works for instance doing so for the image/x-ico tab icon renders the image unable to load properly.
Assuming that the BLOB contains the actual binary data of the image.
Just make sure that the extensions match with the required syntax
jpg file : <img src="data:image/jpeg;base64,[base64_encoded_data]
png file : <img src="data:image/png;base64,[base64_encoded_data]
ico file : <img src="data:image/icon;base64,[base64_encoded_data]
So a sample example is like the following:
<?php
$image=file_get_contents("http://www.createchhk.com/SO/sample1.png");
$file_ext = 'png';
?>
Test for PNG<br>
<img src="data:image/<?php echo $file_ext; ?>;base64,<?php echo base64_encode($image)?>" alt="Landing" width="50px"><br>
<?php
$image2=file_get_contents("http://www.createchhk.com/SO/sample1.jpg");
$file_ext2 = 'jpeg';
?>
Test for JPG<br>
<img src="data:image/<?php echo $file_ext2; ?>;base64,<?php echo base64_encode($image2)?>" alt="Landing2" width="50px"><br>
<?php
$image3=file_get_contents("http://www.createchhk.com/SO/sample1.ico");
$file_ext3 = 'icon';
?>
Test for JPG<br>
<img src="data:image/<?php echo $file_ext3; ?>;base64,<?php echo base64_encode($image3)?>" alt="Landing3" width="50px"><br>
The result can be seen here:
http://www.createchhk.com/SO/testSO_18Nov2021.php
This question already has answers here:
Creating a thumbnail from an uploaded image
(9 answers)
Closed 3 years ago.
I want to display images in my search page as a part of echoed content as a result of search query. These images have different resolutions and what's also very important for the next part they are not squarish. For displaying these photos I've initially used something like this:
if ($queryResult > 0){
while ($row = mysqli_fetch_assoc($result)){
echo '<img src="data:image/jpeg;base64,'.base64_encode($row['photo']).'" ">';
echo "<a href='account.php?username=".$row['username']."&id=".$row['id']."' style='text-decoration:none; color:rgb(0,0,0)'>
<div class='article-box'>
<h3>".$row['username']."</h3>
</div>
</a>";
}
}
But sadly the photos displayed were very big so the result wasn't satisfying me. That's why later I set image displaying part like this:
echo '<img src="data:image/jpeg;base64,'.base64_encode($row['photo']).'" width="150" height="150">';
Again it didn't give me good results. Although the images were then finally small, the non-squarish images were turned into squares what caused them to be deformed. How to display images nicely, I mean to keep them small or of exact size but not to deform them.
Just remove one of the arguments and the browser will scale the image and keep aspect ratio.
echo '<img src="data:image/jpeg;base64,'.base64_encode($row['photo']).'" width="150"';
Or set the height. But not both.
You need to make image thumbs when they are uploaded, not when they are displayed, it ll load faster.
Take a look at this script :
https://pqina.nl/blog/creating-thumbnails-with-php/
Using this script you can now for example generate square 160 by 160 pixel thumbnails with the following command :
createThumbnail('profile.jpg', 'profile_thumb.jpg', 160);
then call profile_thumb.jpg instead of original image
Can someone help me with this code? The problem is it doesn't show the image but this weird stuff: OOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOÿÀx !ÿÄ¢ }!1AQa"q2‘¡#B±ÁRÑð$3br‚%&'()*456789:CDEFGHIJSTUVW
Here is my code:
<?php
//mysql connect database
mysql_connect('localhost','root','password') or die(mysql_error());
mysql_select_db('database') or die(mysql_error());
$res=mysql_query('select * from img');
while($row=mysql_fetch_array($res))
{
echo "<div id='image'>";
echo "<p/>";?> <img src="<?php echo $row['image'];?>" height='300px' width='468px'>";<?php
echo "<p/>"; echo $row['name'];
echo "</div>";
}
?>
<img> expects a URL pointing at where the image file is. You're trying to dump the raw binary garbage of the image into that image tag. That garbage will naturally contain " and > chars in it, and "close" your img tag, letting the rest of the garbage be treated as plain text.
You either have to serve up your image via separate script, e.g.
html:
<img src="pic.php?id=foo">
php:
header('Content-type: image/jpeg');
echo get_blob_from_database($_GET['id']);
Or embed the image inside the html properly:
<img src="data:image/jpg;base64,<?php echo base64_encode($row['image']); ?>">
And neither of these is particularly a good solution. Storing images directly in the database is almost never a good idea.
it's better to save your images in folder rather than save in blob format
you can save the file name in database table and save the images in folder
when you call the filename, you can combine it with src from and get the content
This question already has answers here:
Php : Convert a blob into an image file
(4 answers)
Closed 8 years ago.
I have queried a BLOB my mysql and using the following code I can display the image:
<?php
header("Content-type: image/jpeg");
echo $row['image'];
?>
However, my HTML code below will not display. When i take away this php code, it displays. How can I display the image without preventing my HTML from displaying?
Create a new file, image.php then place the above code in that file.
Then where you want to show your image/html do:
<img src="image.php" />
... rest of your html
For future reference, the same thing holds true when you are creating Javascript/CSS files via PHP.
If you place your php code in a file called image.php, then you can try this
<img src="<?php include 'image.php'; ?>" />
This question already has answers here:
Closed 11 years ago.
Possible Duplicates:
Want to render an image without saving it to disk using PHP GD libs
The image cannot be displayed because it contains errors.
I'd like to call a function that make a image trought the img src tag. Is it possible?
I mean : instead of call <img src="path/file.php" /> I'd like to do somethings like <img src="function()" />
PHP is server side; It can generate either a base64_encoded image result which can be placed as an image, or you can point to a php script that will generate an image. But, regarding client side, it won't work.
So, you could do the following:
// the browser will make a call to your generator to render an image back
echo '<img src="myimagegenerator.php" />';
// src will be something like "data:image/png;base64,..."
echo '<img src="'.generateImage().'" />';
In HTML5 you can put the base64 encoded image source in an image tag. You will just need a function to return that.
function getImage($file){
return 'data:image/gif;base64,' . base64_encode(file_get_contents($file));
}
Your img tag:
<img src="<? echo getImage('path-to-image.gif'); ?>" />
No.
However, you can use the URL "thispage.php?makeimage=1" and call the function and output an image if $_GET['makeimage'] contains 1.