Programmatically uploading and validating a user_picture
You can access the values of the image field settings with:
$user-&gt;getFieldDefinition('user_picture')-&gt;getSettings();

Which will return an array, example:


You then can use file_save_upload
and you can pass to it for second param, an array containing all the validation functions

array $validators: (optional) An associative array of callback
functions used to validate the file. The keys are function names and
the values arrays of callback parameters which will be passed in after
the file entity. The functions should return an array of error
messages; an empty array indicates that the file passed validation.
The callback functions will be called in the order specified in the
array, then the hook hook_file_validate() will be invoked so other
modules can validate the new file.
 source: https://api.drupal.org/api/drupal/core%21modules%21file%21file.module/function/file_validate/8.9.x 

Here are the validation functions you can use:


Source: https://api.drupal.org/api/drupal/core%21modules%21file%21file.module/8.9.x