Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- //_____________________________________________________
- $usuario = $_GET['user'];
- $imagem = Redirect("http://graph.facebook.com/$usuario/picture");
- $dados = file_get_contents( $imagem );
- file_put_contents("imagem.jpg", $dados);
- //_____________________________________________________
- list($width, $height) = getimagesize("imagem.jpg");
- //________________________________________________
- $img = imagecreatefromjpeg("imagem.jpg");
- for($w = 0; $w < $width; $w ++ ) {
- for($h = 0; $h < $height; $h ++ ) {
- $dd = imagecolorat($img, $w, $h);
- $r = ($dd >> 16) & 0xFF;
- $g = ($dd >> 8) & 0xFF;
- $b = $dd & 0xFF;
- echo RGBToHex($r,$g,$b) . "|$w|$h|";
- }
- }
- //_____________________________________________________
- function RGBToHex($r, $g, $b) {
- $hex = str_pad(dechex($r), 2, "0", STR_PAD_LEFT);
- $hex.= str_pad(dechex($g), 2, "0", STR_PAD_LEFT);
- $hex.= str_pad(dechex($b), 2, "0", STR_PAD_LEFT);
- return hexdec($hex."FF");
- }
- //_____________________________________________________
- // Thanks to: http://stackoverflow.com/questions/3519939/make-curl-follow-redirects
- function Redirect($url) {
- $ch = curl_init();
- curl_setopt($ch, CURLOPT_URL, $url);
- curl_setopt($ch, CURLOPT_HEADER, true);
- curl_setopt($ch, CURLOPT_FOLLOWLOCATION, false);
- curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
- $a = curl_exec($ch);
- curl_close( $ch );
- $headers = explode("\n",$a);
- $redir = $url;
- $j = count($headers);
- for($i = 0; $i < $j; $i++){
- if(strpos($headers[$i],"Location:") !== false){
- $redir = trim(str_replace("Location:","",$headers[$i]));
- break;
- }
- }
- return $redir;
- }
- //_____________________________________________________
- unlink("imagem.jpg");
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement