Here is a snippet of my code
<?php
$me = $facebook->api('/me/friends');
foreach( $me['data'] as $frns ) {
?>
<img src="https://graph.facebook.com/"<?php echo $frns['id'] ?>"/picture"
title="<?php echo $frns['name'] ?>"/>
<?php
}
I want to merge all of the images using something like
$im = mergeImages( array( image1, image2, etc ) );
How can I limit the merge to only the first 196 or a random number of images?
Change your code to this. You won't have to make another series of API calls to get the urls for the pictures, and your script won't have to deal with the 301 redirects Facebook typically throws for an image.
$me = $facebook->api('/me/friends?fields=name,picture');
echo "<br />Total friends".sizeof($me['data'])."<br />";
echo "<br /> Friends collage<br /><br />";
$frns_images = array();
$i = 1;
foreach($me['data'] as $frns)
{
if ($i >= 100) break;
$img = $frns['picture']['data']['url']; //Double check this.
if ('jpg' === substr($img, -3)) {
printf ('<img src="%s" title="%s" />', $img, $frns['name']);
$frns_images[] = $img;
$i++;
}
}
$im = mergeImages($frns_images);