0

Hello there i have a php file with the included:

The image shows properly when i access the PHP file, however when I try to show it in the HTML template, it shows as the little img with a crack in it, so basically saying "image not found"

<img src="http://konvictgaming.com/status.php?channel=blindsniper47">

is what i'm using to display it in the HTML template, however it just doesn't seem to want to show, I've tried searching with next to no results for my specific issue, although I'm certain I've probably searched the wrong title

adding code from the OP below

$clientId = '';             // Register your application and get a client ID at http://www.twitch.tv/settings?section=applications
$online = 'online.png';     // Set online image here
$offline = 'offline.png';   // Set offline image here
$json_array = json_decode(file_get_contents('https://api.twitch.tv/kraken/streams/'.strtolower($channelName).'?client_id='.$clientId), true);

if ($json_array['stream'] != NULL) {
    $channelTitle = $json_array['stream']['channel']['display_name'];
    $streamTitle = $json_array['stream']['channel']['status'];
    $currentGame = $json_array['stream']['channel']['game'];

    echo "<img src='$online' />";
} else {
    echo "<img src='$offline' />";
}
2
  • You are not referring to an image. The actual image URL is konvictgaming.com/offline.png Commented Jul 15, 2013 at 11:43
  • You are referring to http://konvictgaming.com/offline.png image Commented Jul 15, 2013 at 11:44

4 Answers 4

6

The url is not an image, it is a webpage with the following content

<img src='offline.png' alt='Offline' />

Webpages cannot be displayed as images. You will need to edit the page to only transmit the actual image, with the correct http-headers.

You can probably find some help on this by googling for "php dynamic image".

Sign up to request clarification or add additional context in comments.

2 Comments

Sorry it seems Stack removed the PHP file that is linked to it which is echoing my Images pastebin.com/cbtKkWS1 As you can see it echo's the image & returns it properly, when X person goes Online/offline on their stream the image changes accordingly, I have previously img scrd a php file like this one, i just can't seem to figure out what is wrong with it in this instance!
Well yes, it's echoing html correctly. So it looks fine when you open it as a webpage. But you need the page to act as an image instead of as a html-page if you want to use it in an <img />.
2

Specify in the HTTP header that it's a PNG (or whatever) image!

(By default they are interpreted as text/html)

2 Comments

Sorry it seems Stack removed the PHP file that is linked to it which is echoing my Images pastebin.com/cbtKkWS1 As you can see it echo's the image & returns it properly, when X person goes Online/offline on their stream the image changes accordingly, I have previously img scrd a php file like this one, i just can't seem to figure out what is wrong with it in this instance!
Add header('Content-Type: image/png'); to the first line in the file you linked.
1

in your status.php file, where you output the markup of <img src=... change it to read as follows

$image = file_get_contents("offline.png");
header("Content-Type: image/png");
echo $image;

Which will send an actual image for the request instead of sending markup. markup is not valid src for an img tag.

UPDATE your code modified below.

$clientId = '';             // Register your application and get a client ID at http://www.twitch.tv/settings?section=applications
$online = 'online.png';     // Set online image here
$offline = 'offline.png';   // Set offline image here
$json_array = json_decode(file_get_contents('https://api.twitch.tv/kraken/streams/'.strtolower($channelName).'?client_id='.$clientId), true);

header("Content-Type: image/png");
$image = null;
if ($json_array['stream'] != NULL) {
    $channelTitle = $json_array['stream']['channel']['display_name'];
    $streamTitle = $json_array['stream']['channel']['status'];
    $currentGame = $json_array['stream']['channel']['game'];

    $image = file_get_contents($online);
} else {
    $image = file_get_contents($offline);        
}
echo $image;

6 Comments

I'm sorry but i'm pretty crap when it comes to php, could you give me the full example of what it would look like? as im unsure as to where it should go / remove/ change xD i basically just want it to Show the image for Online/Offline, the Current game/ Title isnt needed so in theory i just want <img src='$offline'>
i need to see bit more of your code where you echo your current markup
pastebin.com/Mn7gM7D4 But for some reason now im getting Parse error: syntax error, unexpected T_VARIABLE in /home/isykonvi/public_html/stream/status.php on line 3
@DanielStarmer i've added update code you can copy paste directly.
it worked!, thank you so much mate!, although i do have another issue, shall i open a new thing or do you think you can help? it's with the same status.php, I basically want it so that when they access status.php directly from the directory it returns the print: ERROR: Please put a stream user in your link. ex: konvictgaming.com/status.php?channel=konvictgaming
|
1

I suppose you change the picture dynmaclly on this page.

Easiest way with least changes will just be using an iframe:

<iframe src="http://konvictgaming.com/status.php?channel=blindsniper47">    </iframe>

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.