1

该程序将下载用户个人资料图片,然后通过 imagemagick 对其应用效果。由于facebook 示例仅适用于文件库,我不想将其存储为临时文件,如何将二进制格式的最终​​图像上传到 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

?>
4

0 回答 0