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
Related
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">
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
I have this line of code to echo an image (thumb)
printf('<img src="./uploads/designments/%s/thumbs/80x80">',$item['designment_id']);
On the page it will show the broken image icon. and if I look in the elements I see the following path: /uploads/designments/71/thumbs/80x80"
If I look in the ftp to the corresponding file name I see here the path is:
/uploads/designments/71/thumbs/80x80/calculator_wheat_0.jpg
So what do I have to add to my code to get the corresponding filename in the URL?
You closed off the image tag a little too early. Try:
printf('< img src="./uploads/designments/%s/thumbs/80x80/',$item['designment_id'],'">');
I have been trying to change the images in the WampServer Index.php File... When I looked at the Index.php File I saw something Interesting. The File its self was containing the Image in the RAW format. Latter in the Code the PHP Script Calls the Image using the URL like http://localhost/index.php?img=pngFolder called a Image file stored RAW in the PHP file as a png.
Here is a link to a website that has the index.php code...
Link
I would Like to know how to replicate this same process to work for other images. Granted the File will be larger but its a Price to pay for what I am doing for a project. The Reason I want some help with this is so I can do it correctly. I have Tried 2 times already. I managed to get it to call one image correctly but not some of the others. I'm not sure if the image is just a different encoding or what..... Any Help would be Appreciated.
They are using BASE64 to encode the images into text. You can google for a base64 encoder that will convert your images to text. You can then put the text directly in an <img src="..base64 text.." />
Here's one..
https://www.base64-image.de/
As far as getting the image from the url index.php?img=pngfolder..
You could put this at the top of the file
if(isset($_GET['img'])){
echo "...base64 string.."; exit;
}
Then you can use the index url as the src for your image and it will simply retrieve the base64 image
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'; ?>" />