I have a website www.iniciativa-iex.com
, it's connected with twitter, it get's the data using the API for each user and displays his/her profile picture on the scroller. I used to get the data each time the website was called but it was a real problem because it made a lot of calls and my app tokens were deleted very frequently. Now I made it join all the pictures,
include '../twitter/LibTwitter.php';
$sql = mysql_query("SELECT * FROM `users` WHERE `suspended` != 'true' ORDER BY id DESC");
$fullW = mysql_num_rows($sql)*128;
$fullH = 128;$width1 = 0;
$img = imagecreate($fullW, $fullH);
while($result = mysql_fetch_array($sql)) {
$userid = $result["userid"];
$busqueda = $twitter->usersShow($userid, null);
$src = $busqueda["profile_image_url"];
$filetype = str_replace(".", "", substr($src, -4));
if ($filetype == "rmal"){$filetype = "";}
$file = str_replace("_normal.".$filetype, "_reasonably_small.".$filetype, $src);
switch($filetype){
case 'png':
$sub = imagecreatefrompng($file) or die( "Cannot open $filetype file `$file - $src` where USER = `$userid`\n");
break;
case 'gif':
$sub = imagecreatefromgif($file) or die( "Cannot open $filetype file `$file - $src` where USER = `$userid`\n");
break;
case 'jpeg':
case 'jpg':
case 'JPG':
case '':
$sub = imagecreatefromjpeg($file) or die( "Cannot open $filetype file `$file - $src` where USER = `$userid`\n");
break;
}
if(!$sub){die('Missing sub');}imagecopy ( $img, $sub, $width1 , 0, 0, 0, 128, 128);
// imagecopy ( $img, $sub, $width1 , 0, 0, 0, $width, $height) or die( "Cannot copy $filetype file `$file - $src` where USER = `$userid`\n");
$width1 = $width1 + 128;
imagedestroy($sub);
}
imagepng($img, 'users.png');
imagedestroy($img);
EDIT: I got the code working but now it shows a distorted, bad-quality picture, and need CHMOD 0777 to work, anny suggestion?
IMAGE SCROLLER http://www.iniciativa-iex.com/cron/users.png
Thanks!