Advertisement
ipsBruno

(PHP) Pegar BMP Facebook

Dec 7th, 2012
254
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.61 KB | None | 0 0
  1. <?php
  2.  
  3. $usuario = $_GET['user'];
  4.  
  5. $imagem = "http://graph.facebook.com/$usuario/picture";
  6. $arquivo = "tmp.bmp";
  7.  
  8. $imagem_source = imagecreatefromjpeg($imagem);
  9.  
  10. imagebmp($imagem_source, $arquivo);
  11.  
  12.  
  13. // @site: http://www.codingforums.com/archive/index.php/t-157438.html
  14. // @author: kokjj87
  15. function imagebmp( &$im, $filename = "") {
  16.     if (!$im) return false;
  17.     $w = imagesx($im);
  18.     $h = imagesy($im);
  19.     $result = '';
  20.     if (!imageistruecolor($im)) {
  21.         $tmp = imagecreatetruecolor($w, $h);
  22.         imagecopy($tmp, $im, 0, 0, 0, 0, $w, $h);
  23.         imagedestroy($im);
  24.         $im = & $tmp;
  25.     }
  26.     $biBPLine = $w * 2;
  27.     $biStride = ($biBPLine + 3) & ~3;
  28.     $biSizeImage = $biStride * $h;
  29.     $bfOffBits = 66;
  30.     $bfSize = $bfOffBits + $biSizeImage;
  31.     $result .= substr('BM', 0, 2);
  32.     $result .= pack('VvvV', $bfSize, 0, 0, $bfOffBits);
  33.     $result .= pack('VVVvvVVVVVV', 40, $w, '-'.$h, 1, 16, 3, $biSizeImage, 0, 0, 0, 0);
  34.     $numpad = $biStride - $biBPLine;
  35.     //for ($y = $h - 1; $y >= 0; --$y) {
  36.     $result .= pack('VVV', 63488, 2016, 31);
  37.     for ($y = 0; $y < $h; ++$y) {
  38.         for ($x = 0; $x < $w; ++$x) {
  39.             $rgb = imagecolorat($im, $x, $y);
  40.             $r24 = ($rgb >> 16) & 0xFF;
  41.             $g24 = ($rgb >> 8) & 0xFF;
  42.             $b24 = $rgb & 0xFF;
  43.             $col = ((($r24 >> 3) << 11) | (($g24 >> 2) << 5) | ($b24 >> 3));
  44.             $result .= pack('v', $col);
  45.         }
  46.         for ($i = 0; $i < $numpad; ++$i)
  47.         $result .= pack('C', 0);
  48.     }
  49.     if ($filename == "") {} else {
  50.         echo $result;
  51.     }
  52.  
  53.     return true;
  54. }
  55.  
  56. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement