output image in php page - php

thank you so much for your hard work,
my issue hopefully is not that complicated.
I'm trying to display few images in my website, and it won't display,
the php page and the image are on the same directory, and when i try the same directory on html file it works fine, but when I try to use the same directory on php file the pic look broken icon,and won't appear..
I also tried png and jpg image, still nothing coming out..
please guys..
this is the simple code, i tried to test,
<html>
<head><title> hello </title></head>
<body>
<?php $image = 'zz.png'; ?>
<img src= "<?php $image ?>" style="width:304px;height:228px;">
hello world..
</body>
</html>

Print the var $image with echo (and close the image tag with a frontslash at the end of the tag for correct html):
<img src= "<?php echo $image; ?>" style="width:304px;height:228px;" />
Other possible reasons the image is not displayed (after you print the image name out with echo):
the value of your var $image mismatched with the imagename.
the image is not stored in the same folder as the php document.
your image is saved in CMYK mode, and not in RGB.
the file permission of the image
configuration of the webserver (apache for ex.)

You have to print out the $image variable by using the echo function. Your code should be looking like this:
<?php
$image = 'zz.png';
?>
<html>
<head>
<title> hello </title>
</head>
<body>
<img src= "<?php echo $image; ?>" style="width:304px;height:228px;">
hello world..
</body>
</html>
Furthermore, it looks better when you put all your php stuff before the HTML code, that does not necessarily have to be inside HTML.
If it is still not working, you are probably viewing your html file locally. You have to view it remotely by using a http web server with a php interpreter included. You can easily set up one with XAMPP.
Remember that it does not work by just opening your file in a browser.

I think you should replace this line:
<img src= "<?php $image ?>" style="width:304px;height:228px;">
With this:
<img src= "<?php echo($image) ?>" style="width:304px;height:228px;">
Since echo() is the function that generates the output.

Related

HTML PHP Image URL Call

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.

Display images like logo in .php file with html img tag

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

how calling the images in a folder with php

I want to ask about calling the images in a folder with php
The first I've made ​​a file to declare the image url
$url_folder_gambar = 'http://localhost/mysite/assets/img/';
I then call the php but the picture did not come out. what's wrong?
<img src="<?php echo $url_folder_gambar . people.png?>"
please help me
It looks like a syntax error. Try this:
<img src="<?php echo $url_folder_gambar;?>people.png" />
$url_folder_gambar path of the image file, some thing like http://domain/path/imagefolder/
<img src="<?php echo $url_folder_gambar;?>people.png" >
OR
<img src="<?php echo $url_folder_gambar.'people.png';?>" >
Check browser code view source using ctrl+u, check the file path, and copy the source url and pasted into the borwser, whether it is rendered or not, If not there is no file in that location.

Print image from image object in the middle of HTML without saving

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&param2=value2&..."/>

Thumbnail image does not appear on website

I have a problem in my wordpress theme.
The thumbnail doesn't appear on every post.
I have a website with games and every game has a thumbnail (image) . But now the image doesn't appear. When I try to see the image I get this:
Invalid src mime type:
The problematic code is:
<img src="<?php bloginfo('template_url');?>/thumb.php?src=<?=$thumb;?>&w=183&h=140&zc=1" class="thumb" alt="<?php the_title(); ?>" />
What might be wrong?
Browsing to your site I saw what the issue is. If you look at your code, it's being generated like this:
<img src="http://jocuri2k.com/wp-content/themes/Games/thumb.php?src=<?=$thumb?>... ?>
It seems that your PHP parser isn't picking up the php in the tag. Try using this instead:
<img src="http://jocuri2k.com/wp-content/themes/Games/thumb.php?src=<?php=$thumb?>... ?>
It's possible your php configuration doesn't allow for "short-tags"
<?
code here
?>
but instead require the full php tags, which are:
<?php
code here
?>
You might be able to override this in your php.ini, but if you don't have access to that, simply use the full php tags and you should be good to go.
<?php echo $thumb; ?>

Categories