我正在从 facebook 的 graph api 中检索专辑照片。
这段代码可以解决问题,但是我正在尝试选择等于 130 及以上宽度的最小缩略图:130 x 高度:130
意味着宽度或高度必须为 130 及以上,而不是宽度和高度的总和。
注意:数组列表是来自 Facebook 相册的图像变化,因此它们是成比例的。因此,如果它是纵向或横向尺寸,它将相应地按比例缩放。
因此,从print_r
下面您可以看到第一个数组中的第 (2) 项符合该描述,但其他数组将是数字 (2) 和 (1),因为这是 130 宽度/高度以上的最小数组
$userURL2 = "https://graph.facebook.com/$albumID/photos?access_token=" . $fb_oAuth_token;
$ch2 = curl_init($userURL2);
curl_setopt($ch2, CURLOPT_HEADER, 0);
curl_setopt($ch2, CURLOPT_RETURNTRANSFER, 1);
$data2 = curl_exec($ch2);
curl_close($ch2);
$pictures = json_decode($data2, true);
print_r($pictures);
输出自print_r($pictures);
Array
(
[0] => Array
(
[height] => 288
[width] => 460
[source] => https://myurl.jpg
)
[1] => Array
(
[height] => 200
[width] => 320
[source] => https://myurl.jpg
)
[2] => Array
(
[height] => 130
[width] => 180
[source] => https://myurl.jpg
)
[3] => Array
(
[height] => 81
[width] => 130
[source] => https://myurl.jpg
)
)
Array
(
[0] => Array
(
[height] => 500
[width] => 500
[source] => https://myurl.jpg
)
[1] => Array
(
[height] => 500
[width] => 500
[source] => https://myurl.jpg
)
[2] => Array
(
[height] => 480
[width] => 480
[source] => https://myurl.jpg
)
)
Array
(
[0] => Array
(
[height] => 335
[width] => 300
[source] => https://myurl.jpg
)
[1] => Array
(
[height] => 335
[width] => 300
[source] => https://myurl.jpg
)
)
问题:我将如何在 php 中编写这个?
foreach($pictures['data'] as $picture){
$width = $picture['width'];
$height = $picture['height'];
// choose the smallest [source] above width:130 x height:130
}