The following API URL has an output in PNG image:
http://qrfree.kaywa.com/?l=1&s=8&d=google.com
I want convert the API URL to “data:image/png;base64” (DATA URL / DATA URI) with the similar to the PHP code example below:
$image = ("<img src = http://qrfree.kaywa.com/?l=1&s=8&d=google.com"); // False! (only example!)
//or
$image = 'real-picture.png'; // True!
$imageData = base64_encode(file_get_contents($image));
$src = 'data:image/png;base64,'.$imageData;
echo '<img src="'.$src.'">';
However, the above code works with a real picture which has specified format and if replaced with the API URL, cannot read image path.
How the code should be corrected?
Assuming a web request to http://qrfree.kaywa.com/?l=1&s=8&d=google.com returns an image of type image/png, you can do ...
$image = "http://qrfree.kaywa.com/?l=1&s=8&d=google.com";
echo '<img src="data:image/png;base64,',
base64_encode(file_get_contents($image)),
'">';
file_get_contents() expects either a valid file name or a valid http(s) request. Your code was passing in something starting with some HTML <img ...
Related
Below is my json respone:
{"Status":"OK","Result":"{\"Cookie\":MyCookie",\"Data\":{\"ItemPhotos\":[{
\"ITEMID\":\"MyItemsID",
\"ITEMIMAGE\":\"/9j/4AAQSkZJRgABAQEAYABgAAD/2wBDAAgGBgcGBQgHBwcJCQgKDBQNDAsLDBkSEw8UHRofHh0aHBwgJC4nICIsIxwcKDcpLDAxNDQ0Hyc5PTgyPC4zNDL/2wBDAQkJCQwLDBgNDRgyIRwhMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjL/wAARCAC0AUADASIAAhEBAxEB/8QAHwAAAQUBAQEBAQEAAAAAAAAAAAECAwQFBgcICQoL/8QAtRAAAgEDAwIEAwUFBAQAAAF9AQIDAAQRBRIhMUEGE1FhByJxFDKBkaEII0KxwRVS0fAkM2JyggkKFhcYGRolJicoKSo0NTY3ODk6Q0RFRkdISUpTVFVWV1hZWmNkZWZnaGlqc3R1dnd4eXqDhIWGh4iJipKTlJWWl5iZmqKjpKWmp6ipqrKztLW2t7i5usLDxMXGx8jJytLT1NXW19jZ2uHi4+Tl5ufo6erx8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JGkn+8in+lFFWiHuMl0jTyhzZwf8Aftf8Kpf2DpczYazQf7pIoooFdjx4T0gjP2c/99mkbw3pcIylv+ZoooC7KRtYoGIjXaKvWyZA+ZqKKYGnBCCBy1XUt1/vN+dFFIaHiIKeGb8ak8pCORRRTRSIjCIpV2M2HOCvasjVtFswvmqrKSegPFFFY1kuQ1ot8xzd/wCF9OudLnuJxK5XgIWG38sc1b8PaXbWWg2kcClFKbyBgcnrRRSglyoVVtyZzvjXw5p8VgdRijaOcvhghAVvcjHX6V5nMgBPJ4ooqJfEdVB3hqRxsyNwxq2kj7fvUUVnI6okF3fTwRlkfmut8M6LbXNvFeTvLLMwzliCB9BjiiisqmkTeO531haRoi4LfnWkbZNvVulFFYR2Oee41LdORlqelsnmry3UUUV6FL4EeVX/AIjP/9k=\",
\"IMAGEID\":\"ImageID",
\"IMAGEDESCR\":\"xxx.jpg\",
\"IMAGETYPE\":\"TheImageType\",
\"IMAGESIZE\":\"320 x 240\"},]},
\"Messages\":[]}","Error":null,"ErrorCode":null,"Benchmark":0}
I want to diplay the image of json response and i use the code below unsuccessfully
$image=json_decode($decoded['Result']);
$path=$image->Data->ItemPhotos[0]->{'ITEMIMAGE'};
$icon=glob($path."*.jpeg");
foreach($icon as $img) {
echo '<img src="'.$img.'" /><br />';
}
You have two quick solutions for this. One is to persist the encoded image and append the path to the image src. Another solution is to process the json and use the base 64 processor in correct format eg:- 'data:image/png;base64,' + <base 64 encoded image>
or,
'data:image/jpg;base64,' + <base 64 encoded image>
I created a snippet that works with your use case. You have to refactor it a bit to accommodate your changes.
<?php
// Lets assugme you receive this json response
$json = '{
"ITEMIMAGE": "/9j/4AAQSkZJRgABAQEAYABgAAD/2wBDAAgGBgcGBQgHBwcJCQgKDBQNDAsLDBkSEw8UHRofHh0aHBwgJC4nICIsIxwcKDcpLDAxNDQ0Hyc5PTgyPC4zNDL/2wBDAQkJCQwLDBgNDRgyIRwhMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIy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JlK0iXhQ9aHEZ30GoDIIPataC/46157bamMda0oNVA/i4+tYyTRooJnoEV4DjmrccwboeK4qDWFAHz4rRj122UcygfjUczQOl2Onk2upx1qDJ6HqKrWt+lwoKHKnvU7nuOta06vK/I5q1HmXmBpU/1i/UU3OelKn+sX6iu088fb26G0tzluYU/9BFS/Zk9WoooEOFsmerUotkz1aiigY8WyerVItsnq1FFMESi2THVvzp4tU9W/OiimUP+yp6t+dO+yp6t+dFFADhap6t+dZPiKMw6cvlyOu99rYPUY6UUUPYZiWOnxuAfNmH0bFXljZJCizyYBx2/woooewdTThg+XmVz9cf4U82cEhxJGkn+8in+lFFWiHuMl0jTyhzZwf8Aftf8Kpf2DpczYazQf7pIoooFdjx4T0gjP2c/99mkbw3pcIylv+ZoooC7KRtYoGIjXaKvWyZA+ZqKKYGnBCCBy1XUt1/vN+dFFIaHiIKeGb8ak8pCORRRTRSIjCIpV2M2HOCvasjVtFswvmqrKSegPFFFY1kuQ1ot8xzd/wCF9OudLnuJxK5XgIWG38sc1b8PaXbWWg2kcClFKbyBgcnrRRSglyoVVtyZzvjXw5p8VgdRijaOcvhghAVvcjHX6V5nMgBPJ4ooqJfEdVB3hqRxsyNwxq2kj7fvUUVnI6okF3fTwRlkfmut8M6LbXNvFeTvLLMwzliCB9BjiiisqmkTeO531haRoi4LfnWkbZNvVulFFYR2Oee41LdORlqelsnmry3UUUV6FL4EeVX/AIjP/9k=",
"IMAGEID": "ImageID",
"IMAGEDESCR": "xxx.jpg",
"IMAGETYPE": "TheImageType",
"IMAGESIZE": "320 x 240"
}';
$decode = json_decode($json);
// you need base 64 processor
$processor = "";
if($decode->IMAGEDESCR == "xxx.jpg") {
$processor = "data:image/jpg;base64,";
} elseif ($decode->IMAGEDESCR == "xxx.png") {
$processor = "data:image/png;base64,";
}
$img_src = $processor . $decode->ITEMIMAGE;
echo '<img src='.$img_src.'/>';
?>
Your src attribute for the img tag will be something like this
'data:image/png;base64,' + $path;
you must inform that the image is encoded base64 (I suppose it is) and also specify the kind of data (image/png) in my example
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 ?>">
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>
I have a code download image from link http://www.bitrepository.com/download-image.html
When start is link format: <img src='test[1].jpg'>
But when download this link is link become <img src='test3%5B1%5D.jpg'>
How to fix it?
code here
<?php
include_once 'class.get.image.php';
// initialize the class
$image = new GetImage;
$image->source = 'http://test.com/test[1].jpg';
$image->save_to = 'images/'; // with trailing slash at the end
$get = $image->download('gd'); // using GD
if($get)
{
echo 'The image has been saved.';
}
?>
Try this.
On this line
$image->source = 'http://test.com/test[1].jpg';
Changed to
$image->source = htmlspecialchars_decode('http://test.com/test[1].jpg');
Look up urldecode in php to change the encoded values back to brackets
Suppose you have a thumbnail generator script that accepts source images in the form of a URL. Is there a way to detect if the source URL is "broken" - whether nonexistent or leads to an non-image file?
Just brute force using getimagesize() or another PHP GD function is not a solution, since spoofed stray URL's that might not be images at all (http://example.com/malicious.exe or the same file, but renamed as http://example.com/malicious.jpg) could be input - such cases could easily be detected by PHP before having to invoke GD. I'm looking for GD pre-sanitizing before having GD try its battalion at parsing the file.
as a first step, the following regular expression checks if the URL is an image extension:
preg_match('#(https?://([-\w\.]+)+(:\d+)?(/([\w/_\.]*(\?\S+)?)?)?)([^\s]+(\.(?i)(jpg|png|gif|bmp))$)#', $txt,$url);
use file_exists function in php, you can check urls with it.
See documentation below, shows how to check img... exactly what you need
FILE EXISTS - http://www.php.net/manual/en/function.file-exists.php#93572
URL EXISTS - http://www.php.net/manual/en/function.file-exists.php#85246
Here is alternative code for checking the url. If you will test in browser replace \n with <br/>
<?php
$urls = array('http://www.google.com/images/logos/ps_logo2.png', 'http://www.google.com/images/logos/ps_logo2_not_exists.png');
foreach($urls as $url){
echo "$url - ";
echo url_exists($url) ? "Exists" : 'Not Exists';
echo "\n\n";
}
function url_exists($url) {
$hdrs = #get_headers($url);
echo #$hdrs[1]."\n";
return is_array($hdrs) ? preg_match('/^HTTP\\/\\d+\\.\\d+\\s+2\\d\\d\\s+.*$/',$hdrs[0]) : false;
}
?>
Output is as follows
http://www.google.com/images/logos/ps_logo2.png - Content-Type: image/png
Exists
http://www.google.com/images/logos/ps_logo2_not_exists.png - Content-Type: text/html; charset=UTF-8
Not Exists
I have used the following to detect attributes for remote images
$src='http://example.com/image.jpg';
list($width, $height, $type, $attr) = #getimagesize($src);
example (checking stackoverflows "Careers 2.0" image)
$src='http://sstatic.net/ads/img/careers2-ad-header-so.png';
list($width, $height, $type, $attr) = #getimagesize($src);
echo '<pre>';
echo $width.'<br>';
echo $height.'<br>';
echo $type.'<br>';
echo $attr.'<br>';
echo '</pre>';
If $height, $width etc is null the image is obvious not an image or the file does not exists. Using cURL is overkill and slower (even with CURLOPT_HEADER)
The only really reliable way is to request the image using file_get_contents(), and finding out its image type using getimagesize().
Only if getimagesize() returns a valid file type, can you rely that it is in fact a valid image.
This is quite resource heavy, though.
You could consider not doing any server-side checks at all, and adding an onerror JavaScript event to the finished image resource:
<img src="..." onerror="this.style.display = 'none'">
try for local files
<?php
if(file_exists($filename))
{
//do what you want
}
else
{
//give error that file does not exists
}
?>
for external domains
$headers = #get_headers($url);
if (preg_match("|200|", $headers[0])) {
// file exists
} else {
// file doesn't exist
}
Also you can use curl request for the same.
Fast Solution for broken or not found images link
i suggest you that don't use getimagesize() because it will 1st download image then it will check images size+if this will not image then it will throw exception so use below code
if(checkRemoteFile($imgurl))
{
//found url, its mean
echo "this is image";
}
function checkRemoteFile($url)
{
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL,$url);
// don't download content
curl_setopt($ch, CURLOPT_NOBODY, 1);
curl_setopt($ch, CURLOPT_FAILONERROR, 1);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
if(curl_exec($ch)!==FALSE)
{
return true;
}
else
{
return false;
}
}
Note:
this current code help you to identify broken or not found url image this will not help you to identify image type or headers
You could check the HTTP status code (it should be 200) and the Content-type header (image/png etc.) of the HTTP response before you put the actual image through the generator.
If these two preconditions are ok, after retrieving the image you can call getimagesize() on it and see if it breaks, what MIME type it returns etc.
did you try file_get_contents() method?
http://php.net/manual/en/function.file-get-contents.php
onerror Event
Execute a JavaScript if an error occurs when loading an image:
The onerror event is triggered if an error occurs while loading an external file (e.g. a document or an image).
Example:
<!DOCTYPE html>
<html>
<body>
<img src="image.gif" onerror="myFunction()">
<p>A function is triggered if an error occurs when loading the image. The function shows an alert box with a text.
In this example we refer to an image that does not exist, therefore the onerror event occurs.</p>
<script>
function myFunction() {
alert('The image could not be loaded.');
}
</script>
</body>
</html>
Although not detecting broken links, might be useful for someone else...
onerror=""
<img src="PATH" onerror="this.src='NEW PATH'" />