docs: public void setUserImage(CmsObject cms, CmsUser user, String rootPath) throws CmsException {
  
          CmsFile tempFile = cms.readFile(cms.getRequestContext().removeSiteRoot(rootPath));
          CmsImageScaler scaler = new CmsImageScaler(tempFile.getContents(), tempFile.getRootPath());
  
          if (scaler.isValid()) {
              scaler.setType(2);
              scaler.setHeight(192);
              scaler.setWidth(192);
              byte[] content = scaler.scaleImage(tempFile);
              String previousImage = (String)user.getAdditionalInfo(CmsUserIconHelper.USER_IMAGE_INFO);
              String newFileName = USER_IMAGE_FOLDER
                  + user.getId().toString()
                  + "_"
                  + System.currentTimeMillis()
                  + getSuffix(tempFile.getName());
              CmsObject adminCms = OpenCms.initCmsObject(m_adminCms);
              CmsProject tempProject = adminCms.createTempfileProject();
              adminCms.getRequestContext().setCurrentProject(tempProject);
              if (adminCms.existsResource(newFileName)) {
                  // a user image of the given name already exists, just write the new content
                  CmsFile imageFile = adminCms.readFile(newFileName);
                  adminCms.lockResource(imageFile);
                  imageFile.setContents(content);
                  adminCms.writeFile(imageFile);
                  adminCms.writePropertyObject(
                      newFileName,
                      new CmsProperty(CmsPropertyDefinition.PROPERTY_IMAGE_SIZE, null, "w:192,h:192"));
  
              } else {
                  // create a new user image file
                  adminCms.createResource(
                      newFileName,
                      OpenCms.getResourceManager().getResourceType(CmsResourceTypeImage.getStaticTypeName()),
                      content,
                      Collections.singletonList(
                          new CmsProperty(CmsPropertyDefinition.PROPERTY_IMAGE_SIZE, null, "w:192,h:192")));
              }
              if (newFileName.equals(previousImage)) {
                  previousImage = null;
              }
  
              if (CmsStringUtil.isNotEmptyOrWhitespaceOnly(previousImage)) {
                  previousImage = (String)user.getAdditionalInfo(CmsUserIconHelper.USER_IMAGE_INFO);
                  if (CmsStringUtil.isNotEmptyOrWhitespaceOnly(previousImage)
                      && cms.existsResource(newFileName, CmsResourceFilter.ONLY_VISIBLE_NO_DELETED)) {
                      try {
                          adminCms.lockResource(previousImage);
                          adminCms.deleteResource(previousImage, CmsResource.DELETE_REMOVE_SIBLINGS);
                      } catch (CmsException e) {
                          LOG.error("Error deleting previous user image.", e);
                      }
                  }
              }
              user.setAdditionalInfo(CmsUserIconHelper.USER_IMAGE_INFO, newFileName);
              adminCms.writeUser(user);
  
              try {
                  OpenCms.getPublishManager().publishProject(adminCms);
              } catch (Exception e) {
                  LOG.error("Error publishing user image resources.", e);
              }
  
          }
      }