i am trying to get a Minecraft player's skin via PHP, and it all works, until the user enteres an invalid username, techniclly, if that happenes the script should replace the not found image with an alternative image, but for some reason it doesn't.
full script:
<?php
//initial settings
header("Content-type: image/png");
//declere values
$name = $_GET['n'];
//get the image from Minecraft main servers
$src = imagecreatefrompng("http://s3.amazonaws.com/MinecraftSkins/{$name}.png");
//if not found, use an alternative image
if(!$src){
$src = imagecreatefrompng("http://s3.amazonaws.com/MinecraftSkins/char.png");
}
//display the skin
imagepng($src);
?>
Any help will be appriciated, thank you.
try
<?php
//initial settings
header("Content-type: image/png");
//declere values
$name = $_GET['n'];
//get the image from Minecraft main servers
if(file_exists("http://s3.amazonaws.com/MinecraftSkins/{$name}.png")) {
$src = imagecreatefrompng("http://s3.amazonaws.com/MinecraftSkins/{$name}.png");
//if not found, use an alternative image
else {
$src = imagecreatefrompng("http://s3.amazonaws.com/MinecraftSkins/char.png");
}
//display the skin
imagepng($src);
?>
Related
after no one answered at this question Php Rss feed use img in CDATA -> content:encoded i try to do something else solving this problem...
how can i load an image from a given url directly into my homepage?
<?php
$url = "...";
$image = file_get_contents("$url");
echo $image;
?>
*i don't want to save the image anywhere... just load the image from the url and show it in my own homepage.
Try this code,work fine on my machine.
<?php
$image = 'http://www.google.com/doodle4google/images/d4g_logo_global.jpg';
$imageData = base64_encode(file_get_contents($image));
echo '<img src="data:image/jpeg;base64,'.$imageData.'">';
?>
You are almost there. When you download the contents of the file you need to encode it to base64 if you do not plan to store it on server.
<?php
$url = '...';
$image = base64_encode(file_get_contents($url));
?>
Then you can display it:
<img src="data:image/x-icon;base64,<?= $image ?>">
I created a php page that print the barcode. Just to view it before i print it on an A4. Still in testing phase. The codes are as below.
<?php
include('include/conn.php');
include('include/Barcode39.php');
$sql="select * from barcode where b_status = 'NOT-PRINTED'";
$result=mysqli_query($conn,$sql);
echo mysqli_num_rows($result);
$i=0;
while($row=mysqli_fetch_assoc($result)){
$acc_no = $row["b_acc_no_code"];
$bc = new Barcode39($row["b_acc_no_code"]);
echo $bc->draw();
$bc->draw($acc_no.$i.".jpg");
echo '<br /><br />';
$i++;
}
?>
Without the while loop, it can be printed, but only one barcode. How to make it generate, for example in the database have 5 values, it will print 5 barcode in the same page. Thanks in advance
Try to use another bar code source. Because It is generate only one bar code per page. Can't able to create multiple bar code per page.
I know this is an older post but comes up in searches so is probably worth replying to.
I have successfully used the Barcode39 to display multiple barcodes. The trick is to get base64 data from the class and then display the barcodes in separate HTML tags.
The quickest way to do this is to add a $base64 parameter to the draw() method:
public function draw($filename = null, $base64 = false) {
Then, near the end of the draw() method, modify to buffer the imagegif() call and return the output in base64:
// check if writing image
if ($filename) {
imagegif($img, $filename);
}
// NEW: Return base 64 for the barcode image
else if ($base64) {
ob_start();
imagegif($img);
$image_data = ob_get_clean();
imagedestroy($img);
return base64_encode($image_data);
}
// display image
else {
header("Content-type: image/gif");
imagegif($img);
}
Finally, to display multiples from the calling procedure, construct the image HTML in the loop and display:
// assuming everything else has been set up, end with this...
$base64 = $barcode->draw('', true); // Note the second param is set for base64
$html = '';
for ($i = 0; $i < $numBarcodes; $i++) {
$html .= '<img src="data:image/gif;base64,'.$base64.'">';
}
die('<html><body>' . $html . '</body></html>');
I hope this helps anyone else facing this challenge.
Below is the code that I am using to grab the screen shot of the entire webpage.
reference stackoverflow link (Website screenshots using PHP)
When I run this script from browser, All I get is a blank black image and not the screen shot of the webpage. Any help is greatly appreciated. Thanks!
<?php
header('Content-Type: image/jpeg');
$Browser = new COM('InternetExplorer.Application');
$Browserhandle = $Browser->HWND;
$Browser->Visible = true;
$Browser->Fullscreen = true;
$Browser->Navigate('http://google.com');
while($Browser->Busy){
com_message_pump(4000);
}
$img = imagegrabwindow($Browserhandle, 0);
$Browser->Quit();
imagejpeg($img, 'screenshot3.jpg');
?>
According to php.net ( http://php.net/manual/en/function.imagegrabwindow.php ):
the imagegrabwindow function "is only available on Windows."
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' />";
}
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".
Specify in the HTTP header that it's a PNG (or whatever) image!
(By default they are interpreted as text/html)
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;
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>
Good day!
Could anyone help me, there is a system where users do register via their desktop in a database hosted on the web, we are now developing the web interface of this system, then it has a certain functionality in the system where I have to display the photo user.
I do what normal SELECT in SQL Server, but upon the imagejpeg ($ img); it does not show the whole picture, just a piece of the picture. Could anyone help me? I'm looking for some tutorials on the web and they speak it is because of the size of the field. If the field is of type (image) and the return is in hexadecimal.
Below I tried to do a function with the help of a friend, but she also did not work:
<php
$id = (int)$_GET['id'];
$qryimg = mssql_query(gimage SELECT FROM user WHERE id = {$ id});
$resimg = mssql_fetch_array($qryimg);
$im1 = $resimg['gimage'];
header("Content-type: image/jpg");
$image='';
for($i=2; $i<strlen($im1); $i+=2)
{
$hex = $im1{$i} . $im1{($i + 1)};
$cod = hexdec( $hex );
$image .= chr( $cod );
}
echo $image;
#echo imagejpeg($image);
?>
Why doesn't the following code work? Can't you just echo the image.
<php
$id = (int)$_GET['id'];
$qryimg = mssql_query(gimage SELECT FROM user WHERE id = {$ id});
$resimg = mssql_fetch_array($qryimg);
$im1 = $resimg['gimage'];
header("Content-type: image/jpg");
print $im1;
exit;
What field type is gimage?