change imagecopyresized to imagecopyresampled for better quality