Displaying an Image HTML [duplicate] - php

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'; ?>" />

Related

Why can't the image be displayed on img tag in html using php document root on windows 10 using wamp64?

I can't seem to display the image.
I'm writing this code in document_root/admin and the img file is located on document_root/img/food
When I tried using this code
<img src="<?php echo htmlentities("$_SERVER[DOCUMENT_ROOT]/".$row['food_img']); ?>" width="100px"></img>
The HTML from the PHP shows this
This is the output
before you bash me, I'm just a student.. still trying to learn PHP and the CRUD for image file

How can I display an image I just created? [duplicate]

This question already has answers here:
Displaying an image created with imagecreatefromstring
(4 answers)
Closed 2 years ago.
I have a PHP page containing a form(method post).
On the submit of the button, I create an image using imagecreatetruecolor and imagesetpixel.
Then, I want to show this picture after the form.
I tried saving the image to a file using imagepng($img, 'test.png'); and echo '<img src="test.png">';, but that doesn't get the new image. How can I achieve that?
You need to determine where your image is being created when you call imagepng(), then ensure your image tag has the correct path to it.
For example:
$root = $_SERVER['DOCUMENT_ROOT'];
imagepng($img, $root . '/images/test.png')
Your image will then be available at:
https://example.com/images/test.png
And you can set your image source accordingly:
<img src="/images/test.png">

Can't view an image in localhost [duplicate]

This question already has answers here:
PHP code is not being executed, but the code shows in the browser source code
(35 answers)
Closed 7 years ago.
I changed my *.html file into *.php. It seemed okay, but after I click the button for image it doesn't show the picture. IN *.html file it was working.
My code:
<img src="C:\xampp\htdocs\Bella Cristina/diamond.jpg" alt="Diamond Room" style="width:200px;height:200px;">
Firstly, you have to make sure that the image exist in your image folder. Insert the name of the folder and the image into a field in your table in the database.
To display it write thees lines of PHP code:
// this will display the image with the size reduced or increased by 180px by 180px
echo '<img src="'.$row['field'].'" '.'width="180px"'.' '.'height="180px"'.'>';
?>
Note: the $connection much be existing in your connection string that is connecting the database

Change PHP GD image output file url name/link

I have this problem, i have this script in php that creates a image on the fly, the problem is that the outputted image on the browser is allright, but i need to change it's name.
Ex: Index.php
<?php $url = "http://www.somesite.com/cls/image_scrc?_aaa=qJ7VgSxWBLG3FfNQVB%2BKI58kfHQulPHZLuLYaZAG6Tk%3D&_ab=3ctGTf547wdsAGjY%2F5FASE%2BpBnbQEAcrhbJzCHQ7mGs%3D&_acb=89e62acf3b4d254abf0c3ab30d6ebb33" ?>
<img src="<?php echo $url ?>" />
The image_scrc.php is the file that creates the image, and as you can see i have several data that is passed by the get method.
In the image_scrc.php i have tryed
header('Content-type: image/jpg');
header('Content-Disposition:inline; filename="'.$random_name_jpeg.'"');
but the html link is is always appearing like this
http://www.somesite.com/cls/image_scrc?_aaa=qJ7VgSxWBLG3FfNQVB%2BKI58kfHQulPHZLuLYaZAG6Tk%3D&_ab=3ctGTf547wdsAGjY%2F5FASE%2BpBnbQEAcrhbJzCHQ7mGs%3D&_acb=89e62acf3b4d254abf0c3ab30d6ebb33
if i select the image on browser and then select copy image link it copies just like this also.
however, when I save the image it assumes the random_name.jpg, but only on save!
i've tried everything, even htaccess rules but nothing seems to work !!
it's this possible to acomplish? transform this
http://www.somesite.com/cls/image_scrc?_aaa=qJ7VgSxWBLG3FfNQVB%2BKI58kfHQulPHZLuLYaZAG6Tk%3D&_ab=3ctGTf547wdsAGjY%2F5FASE%2BpBnbQEAcrhbJzCHQ7mGs%3D&_acb=89e62acf3b4d254abf0c3ab30d6ebb33
to this
http://www.somesite.com/cls/random_name.jpg
i cant have the image on the server side! and must be displayed on the fly
Thanks in advance.

PHP - call a function from a img src [duplicate]

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.

Categories