I'm generating a png image using php that works here:
http://www.sidesay.co/BTC_spark.php
However I am attempting to then insert the generated png file into a table on a webpage (I'm unsure if that's terribly inefficient). I use the php line:
echo "<td><img src=\"https:\/\/www.sidesay.co\/BTC_spark.php\" ></td>";
I get a broken image, but if I right click and select "load image" it works.
Should I instead first run the php file and save the image separately before destroying it? If so, how?
Thanks in advance.
Your BTC_spark.php script is outputing HTML itself:
<html>
<body>
<img src='/libraries/Sparkline/sparkline.php?size=80x20&data=2,4,5,6,10,7,8,5,7,7,11,8,6,9,11,9,13,14,12,16&back=fff&line=5bb763&fill=d5f7d8' />
</body>
</html>
Change it to just output the img src:
/libraries/Sparkline/sparkline.php?size=80x20&data=2,4,5,6,10,7,8,5,7,7,11,8,6,9,11,9,13,14,12,16&back=fff&line=5bb763&fill=d5f7d8
... and then in your main script, stick this output in a variable:
$mypic = file_get_contents('./BTC_spark.php');
echo '<td><img src="'.$mypic.'"></td>';
Related
I have an image URL, for example, http://URL/123.jpg. I can view the image in the browser, but it's not working when using the <img> tag in PHP. It's not working, and the idea is somehow not displayed.
echo "<img src=\"http://URL/123.jpg\" style=\"width:11%;height:auto;margin-left: 570px;margin-top: 170px;\">";
Any idea?
For php I use '' and for html the "" quotation marks.
Don't know if it's gonna solve your issue tho. Maybe the height:auto; is the problem. I think you can even delete it, if you set the width the height should be auto by default.
echo '<img src="http://test.com/123.jpg" style="width:11%;margin-left: 570px;margin-top: 170px;" />';
Use Normal HTML syntax, include your php then save file as .php
<!DOCTYPE html>
<html>
<body>
<img src="https://external-content.duckduckgo.com/iu/?u=https%3A%2F%2Ftse1.mm.bing.net%2Fth%3Fid%3DOIP.GONAZbNLqDhBj8q4CpTnCQHaLH%26pid%3DApi&f=1" style="width:100px;height:auto;margin-left: 570px;margin-top: 170px;"/>
<!--your php file-->
<?php include 'footer.php';?>
</body>
</html>
Don't forget you have to save this file as PHP.
I am very new to PHP where the same issue have been facing. Coding a simple welcome php page with a logo in png or jpg format does not show in both development and production server.
Tried using changing the permissions to the folders and files but nothing results.
Any idea?
to do this, you could simply include a PHP echo code segment in your HTML file. for instance,
<html>
<div id="banner">
<?php echo '<image src="logo.jpg" />'; ?>
</div>
</html>
I've used this code to display my logo:
echo "<img src="https://yangtzesolutions.com/wp-content/uploads/2021/07/logo-150x150.png" <?php imageResize(100,100, 150); ?>>";
It will display image from the source URL: https://yangtzesolutions.com/wp-content/uploads/2021/07/logo-150x150.png
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
I use the imagic extension. I have an $image_obj object. I can just echo it but it makes it look like random number of characters unless I put:
$Obj_img->setImageFormat("png");
header("Content-Type: image/png");
echo $image_obj;
Is there way to actually put it like this:
echo "<html>
<body>
this is my image: {$image_obj}
</body>
</html>";
I know you can do
echo "this is my image <img src="raw:{$image_obj}" />
but is there any other way without saving document to a file?
Make an image.php script that generates the image, and point to it inside your html:
<img src="image.php?param1=value1¶m2=value2&..."/>
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.