<?php // demo/temp_fitbit.php
/**
* http://www.experts-exchange.com/questions/28933168/extract-webpage-icon.html#a41507902
*/
error_reporting(E_ALL);
$url = 'http://www.fitbit.com/favicon.ico';
$doc = file_get_contents($url);
$doc = substr($doc,0,120);
$hex = new Hexdump($doc);
$hex->render();
$lnk = PHP_EOL . PHP_EOL . '<a target="_blank" href="' . $url . '">Icon in new window</a>';
echo $lnk;
Class Hexdump
{
public function __construct($str)
{
$this->str = $str;
$this->arr = preg_split('~~u', $str, -1, PREG_SPLIT_NO_EMPTY);
$this->getChrs();
$this->getScale();
$this->getNibbles();
return $this;
}
// RETURN SPACED CHARACTERS
public function getChrs($dot='_')
{
$out = NULL;
foreach ($this->arr as $chr)
{
$out .= $chr;
$len = strlen($chr)-1;
while ($len > 0)
{
$out .= $dot;
$len--;
}
}
$this->len = strlen($out);
$this->out = $out;
return $out;
}
public function getScale()
{
$this->num = substr('1...5...10...15...20...25...30...35...40...45...50...55...60...65...70...75...80...85...90...95..100..105..110..115..120..125..130', 0, $this->len);
}
public function getNibbles()
{
// GET THE HEX BYTE VALUES IN A STRING
$hex = str_split(implode(NULL, unpack('H*', $this->str)));
// ALLOCATE BYTES INTO HI AND LO NIBBLES
$this->hi = NULL;
$this->lo = NULL;
$mod = 0;
foreach ($hex as $nib)
{
$mod++;
$mod = $mod % 2;
if ($mod)
{
$this->hi .= $nib;
}
else
{
$this->lo .= $nib;
}
}
}
public function render($br = PHP_EOL)
{
echo $br . '<pre>';
echo $br . $this->num;
echo $br . $this->out;
echo $br . $this->hi;
echo $br . $this->lo;
echo $br;
}
}
Outputs:
1...5...10...15...20...25...30...35...40...45...50...55...60...65...70...75...80...85...90...95..100..105..110..115..120..125..130
‰PNG
IHDRóÿa@IDAT8ÒO+¦QðIÖ’,|ƒÁrJ63HOŠzD½a&YcáL¬hŠ¥”“”N)M±šÅ”Ér’…Ædõ.¤XÈâ9Ê;õ<¹7çÏ}ŸëÜ×_______________________________________________________________________________________________________________________
854400100000444500010001000001ff600044445388d42a510f14d9278c743344874b116256e04a681a999424b9c9c798c6f2a5ce3c3f3b3ec79edd
90e7daaa000d98420000000086000f3f1001094148dd2fb61860f962cc312a638faa4d1f169313cc8a45434e9d1a549225645e48829ab5c977fdfbc7
Icon in new window
You can try the script on my server, here:<!DOCTYPE html>
<meta charset="utf-8">
<canvas width="120" height="30"></canvas>
<script>
var canvas = document.querySelector("canvas"),
context = canvas.getContext("2d");
var image = new Image;
image.src = "fallback.svg";
image.onload = function() {
context.drawImage(image, 0, 0);
var a = document.createElement("a");
a.download = "fallback.png";
a.href = canvas.toDataURL("image/png");
a.click();
};
</script>
save it as .html and save the .svg file in the same directory and open the html page then you can save it as .png
you can't get the the image cause it's in the css style
Just right click on the image
>press inspect
>get the name of the class
>find it in the style
>search for background in that class you should find an url to the image open it in new tab and save it .
this image will illustrate what i wrote