Q:

WHats the most efficient way to store profile images for a social networking website?

I've built up a simple social network and have given users the ability to upload profile photographs. The thing is that I've set it up so that upon upload the picture is resized to two sizes which are used in my website design. However the client requires a design change after a while. The new design thought up requires a different size for the images. This is like after 2 years of running the website and we have a good number of users with profile pictures.
At this point I think I've made a mistake in resizing the images to the fixed sizes as now I will have to make provisions for resizing all the images already on the system to be set up with the new design. WHich begs the question - what would be the best way to maintain images on the server which would be viewed at different sizes?

A:

If you want to save the hassle of resizing them all at once, you can have a conditional that checks if its been resized yet to the new size, and then resize it when the image is accessed for the first time.
  $edit_file = $_edit_id.'_'.basename($_FILES['edit_imagename']['name']);
  $uploadfile = $orig_uploaddir . $edit_file;
  if (move_uploaded_file($_FILES['edit_imagename']['tmp_name'], $uploadfile)) 
    {
    //---resize image to regular and thumbnail-----------------------------------b
    $src = imagecreatefromjpeg($uploadfile);
    $image_info=getimagesize($uploadfile);
    list($width,$height)=$image_info;
    //---create 400x400 fullsize--------------b
    $newwidth=400;
    $newheight=round(($height/$width)*$newwidth);
    if ($newheight>400)
      {
      $newheight=400;
      $newwidth=round(($width/$height)*$newheight);
      }
    $tmp=imagecreatetruecolor($newwidth,$newheight);
    imagecopyresampled($tmp,$src,0,0,0,0,$newwidth,$newheight,$width,$height);
    $filename = $uploaddir . $_edit_id.'_400_'.basename($_FILES['edit_imagename']['name']);
    imagejpeg($tmp,$filename,100);
    //---create 400x400 fullsize--------------e
    //---create 200x200 thumbnail--------------b
    $tn_width=200;
    $tn_height=round(($height/$width)*$tn_width);
    if ($tn_height>200)
      {
      $tn_height=200;
      $tn_width=round(($width/$height)*$tn_height);
      }
    $tmp=imagecreatetruecolor($tn_width,$tn_height);
    imagecopyresampled($tmp,$src,0,0,0,0,$tn_width,$tn_height,$width,$height);
    $filename = $uploaddir . $_edit_id.'_200_'.basename($_FILES['edit_imagename']['name']);
    imagejpeg($tmp,$filename,100);
    //---create 200x200 thumbnail--------------e
    imagedestroy($tmp); 

