简体   繁体   English

Facebook-通过ID获取照片并设置宽度和高度

[英]Facebook - get photo by id and set width & height

I have to get a photo by id and set width and height of this photo. 我必须按ID获取一张照片,并设置这张照片的宽度和高度。

I tried that: 我尝试过:

$photo_thumb = file_get_contents('https://graph.facebook.com/'.$attachments[$i]['target']['id'].'/picture?width=400&height=200&redirect=false&access_token='.$token);
$photo_thumb = json_decode($photo_thumb, true);

and finally i get this: 最后我得到这个:

array(1) {
  ["data"]=>
  array(2) {
    ["is_silhouette"]=>
    bool(false)
    ["url"]=>
    string(110) "https://scontent.xx.fbcdn.net/hphotos-xtl1/t31.0-8/s720x720/12496360_127798700941215_6417691067208545145_o.jpg"
  }
}

This returned photo is 720 x 720. Why? 返回的照片为720 x720。为什么? I set 400 x 200. Anyone can tell me why it doesn't work and how repair it? 我设置为400 x200。任何人都可以告诉我为什么它不起作用以及如何修复?

Thanks. 谢谢。

Facebook does not return just any width or height you define in the parameters. Facebook不会仅返回您在参数中定义的任何宽度或高度。 Why don't you try testing here: 您为什么不尝试在这里进行测试:

https://developers.facebook.com/tools/explorer/145634995501895/?method=GET&path=user_id%2Fpicture https://developers.facebook.com/tools/explorer/145634995501895/?method=GET&path=user_id%2Fpicture

The image width and height you specify are more suggestions than requirements in this API call. 在此API调用中,您指定的图像宽度和高度比要求更多的建议。 If you need an image of a specific aspect ratio or width and height, you'd be better off downloading the image and manipulating it yourself using an extension like GD2. 如果您需要特定长宽比或宽度和高度的图像,最好下载图像并使用GD2之类的扩展程序自己进行操作。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM