Category Archives: PHP

Image resize script – PHP

<?php
 class SimpleImage {
 function resizeImage($max_width,$max_height,$url,$destination){
  $quality = 95; $source_pic = ''.$url.'';
  $src = imagecreatefromjpeg($source_pic);
  list($width,$height)=getimagesize($source_pic);
  $x_ratio = $max_width / $width; $y_ratio = $max_height / $height;
  if( ($width <= $max_width) && ($height <= $max_height) ){
   $tn_width = $width; $tn_height = $height; }
  elseif (($x_ratio * $height) < $max_height){
   $tn_height = ceil($x_ratio * $height); $tn_width = $max_width; }
  else {
   $tn_width = ceil($y_ratio * $width); $tn_height = $max_height; } $tmp=imagecreatetruecolor($tn_width,$tn_height);
  imagecopyresampled($tmp,$src,0,0,0,0,$tn_width, $tn_height,$width,$height);
  imagejpeg($tmp,$destination,$quality); imagedestroy($tmp);
 }
}
 $image = (object) new resizeImage();
 $image->resizeImage(100,80,$source,$destination);
?>

Latest tweets in your site – PHP

<?php

$username=”tppramod”; // Your Twitter username

$limit=10;//Number of tweets

if(!is_numeric($limit)){$limit = 10;}

$xml = simplexml_load_file(‘http://search.twitter.com/search.atom?q=from%3A’.urlencode($username));?>

<table>

<?php for($i=0;$i<$limit;$i++){

if(empty($xml->entry[$i]->content)) break;

$attr = $xml->entry->link[1]->attributes();

?>

<tr> <td> <img src=”<?php echo $attr[‘href’]; ?>” /> </td> <td style=” font-size:12px;”> <?php echo  $xml->entry[$i]->content; ?> </td> </tr>

<?php } ?>

</table>