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.
Related
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'; ?>" />
How can I make a PHP page that will return image from other server specified by url in variable, like this:
http://www.mypage.com/MyScript.php?src=http://www.otherpage.com/image.png
And after going to that page an image should apear.
It need to work for any other srcs too.
(Why like this?
I want to try bypass the Security Error that apears using toDataUrl from canvas while using image not from the same domain, by using http://www.mypage.com/MyScript.php?src=http://www.otherpage.com/image.png as a image src used in canvas)
You can try with
echo file_get_contents($_GET['src']);
In MyScript.php, use $_GET['src'] as the source of the image
<img src="<? echo $_GET['src']; ?>" />
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.
Ive got a php file 'get.php' that echo's a base64 string.
How would i display this as an image in another .php page?
something like this:
<img src="get.php?id=$lastid">
thanks for your help!
You can do something like this:
<img src="data:image/png;base64,BASE64STRING">
but if you BASE64STRING is the output of a php, then something like this would work:
<img src="data:image/png;base64, <?php include 'get.php?id=$lastid' ?>>
I know it may not be exactly but I hope you get the idea
If you want to display that as an image you will need to look into GD Library and generate a run time image using a function like imagettftext() after the image has been generated, your PHP script will send a header saying this is an image something like
header( "Content-type: image/jpeg");
and then echo the binary data of the generate image.
I found this question for you which should help you get started, look at the accepted answer:
Text on a image
No, you need to echo the output of get.php directly. Why don't you just include and call that function on the original page in source? Don't forget that the base64 string needs data:image/png;base64, or similar at the beginning.
<?php
include_once('get.php');
echo '<img src="'.base64img($lastid).'">';
All,
I am executing a PHP script through CURL which returns a PNG file as an output. How can I show the png file in a php web page?
echo '<img src="urltotheimage.php" alt="Alt text" />';
First of all, why do you need to fetch a PNG through CURL? There's better ways to get a image from server, for example using the <img /> tag..
Anyways, I assume you are getting the binary data in a variable, you can output the image by setting appropriate headers and echoing the data:
header('Content-type: image/png');
echo $image;
as you are receiving the string representing the png and if that is base64 encoded then you can embed directly on the image tag as follows:
<img src="data:image/png;base64,aAbBcCdDeEfFgGhH..." />
where aAbBcCdDeEfFgGhH... would be the image string.
see more on data uri's here: http://en.wikipedia.org/wiki/Data_URI_scheme#Inclusion_in_HTML_or_CSS_using_PHP