Optimum electron bunch creation in a photoinjector using space charge expansion