If you want to save the problem of resizing them all at the same time, you may have a condition that checks whether it has changed before the new size, and then resize it the first time you access the image.
$edit_file = $_edit_id.'_'.basename($_FILES['edit_imagename']['name']);
$uploadfile = $orig_uploaddir . $edit_file;
if (move_uploaded_file($_FILES['edit_imagename']['tmp_name'], $uploadfile))
{
$src = imagecreatefromjpeg($uploadfile);
$image_info=getimagesize($uploadfile);
list($width,$height)=$image_info;
$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);
$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);
imagedestroy($tmp);
source
share