views:

64

answers:

4

Hi guys, 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: 

I don't think there are any social networks that ever change their image sizes throughout a design change... and there's a pretty good reason for this.

I guess you could keep the highest resolution version of an image and batch process a load of new images from that, have the image dimensions as part of the file name so they can easily be grouped.

ILMV
General good practice here (if you can afford the storage based on your user base size) is to keep an "original" version that is larger than you'd ever want to actually display on the site so that you can reprocess if the need ever occurs later on due to a redesign.
AvatarKava
+1  A: 

Depending upon the sheer number of images (if it's too many, this may not be practical), I'd hang on to the original images in a permanent spot, and keep the resized images in a different cached spot for the next time your client decides to change the specs. :-)

If space is limited and you are not concerned about caching the resized images, you could just resize them with php's GD library on the fly.

umop
A: 

I find it best to create a thumbnail script and resize the photo on the fly, this way you can store more pictures. It'll decrease your HDD usage by 50%; but it'll add a few milliseconds to your page load.

Zane Edward Dockery
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); 
Talvi Watia