Discover & Rate New Music Check out ChartVote. Promote the music you like.

Post Photos from your Phone to Twitter with TwitPic

The biggest feature request for TwitPic has been the ability to post pictures from your phone to Twitter. Well as of yesterday, you now have that ability.

Just login to TwitPic, click on Settings and you are presented with your own unique TwitPic email address that you can post images to from your phone or from any capable email client.

TwitPic - Share photos on twitter from your phone

Traffic and image posts have spiked and already this new feature has been a great success.

PHP Crop Image

This function will crop an image to the specified width and height without distorting it and in most cases without adding black regions to the image. This function is great for profile photos where the image needs to fit a certain area, but the images being uploaded are of all sizes.

Example
cropexample.jpg

Code

PHP:
  1. cropImage(225, 165, '/path/to/source/image.jpg', 'jpg', '/path/to/dest/image.jpg');
  2.  
  3. function cropImage($nw, $nh, $source, $stype, $dest) {
  4.  
  5.     $size = getimagesize($source);
  6.     $w = $size[0];
  7.     $h = $size[1];
  8.  
  9.     switch($stype) {
  10.         case 'gif':
  11.         $simg = imagecreatefromgif($source);
  12.         break;
  13.         case 'jpg':
  14.         $simg = imagecreatefromjpeg($source);
  15.         break;
  16.         case 'png':
  17.         $simg = imagecreatefrompng($source);
  18.         break;
  19.     }
  20.  
  21.     $dimg = imagecreatetruecolor($nw, $nh);
  22.  
  23.     $wm = $w/$nw;
  24.     $hm = $h/$nh;
  25.  
  26.     $h_height = $nh/2;
  27.     $w_height = $nw/2;
  28.  
  29.     if($w> $h) {
  30.  
  31.         $adjusted_width = $w / $hm;
  32.         $half_width = $adjusted_width / 2;
  33.         $int_width = $half_width - $w_height;
  34.  
  35.         imagecopyresampled($dimg,$simg,-$int_width,0,0,0,$adjusted_width,$nh,$w,$h);
  36.  
  37.     } elseif(($w <$h) || ($w == $h)) {
  38.  
  39.         $adjusted_height = $h / $wm;
  40.         $half_height = $adjusted_height / 2;
  41.         $int_height = $half_height - $h_height;
  42.  
  43.         imagecopyresampled($dimg,$simg,0,-$int_height,0,0,$nw,$adjusted_height,$w,$h);
  44.  
  45.     } else {
  46.         imagecopyresampled($dimg,$simg,0,0,0,0,$nw,$nh,$w,$h);
  47.     }
  48.  
  49.     imagejpeg($dimg,$dest,100);
  50. }

RSS Feed



Recommended Sites