如何将图像数据的原始字节上传到Facebook

时间:2013-11-14 03:03:51

标签: php facebook

程序将下载用户个人资料图片,然后通过imagemagick对其应用效果。由于facebook example仅用于文件库,我不想将其存储为临时文件,如何将二进制格式的最终​​图像上传到Facebook?

<?php 
  //1. prepare frame
  $overlay = new Imagick('1.png');

  //2. prepare base image
  $base = new Imagick();
  $base->readImageFile(fopen('https://graph.facebook.com/'.$id.'/picture?type=large', 'rb'));


  //3. finalize the image
  $base->compositeImage($overlay, Imagick::COMPOSITE_DEFAULT, 0, 0);


  //4. prepare form data
  $options = array(
    CURLOPT_URL         => "https://graph.facebook.com/me/staging_resources",
    CURLOPT_POST        => true,
    CURLOPT_HTTPHEADER  => Array("Content-Type: multipart/form-data"),
    CURLOPT_POSTFIELDS  => array(
      'file' => 'data:image/png;base64,'.base64_encode($base),
      'access_token' => ''
    )
  );

  //5. send to staging_resources 
  $ch = curl_init(); 
  curl_setopt_array($ch, $options);
  echo curl_exec($ch);

  //6. create og object

?>

0 个答案:

没有答案