def METHOD_NAME(image_buf, user_id, department_id=None):
    """
    Just a quick explanation of the order of operations here...
    we have to scrub the image before we do anything else like hash it,
    but we also have to get the date for the image before we scrub it.
    """
    image_buf.seek(0)
    try:
        pimage = Pimage.open(image_buf)
    except UnidentifiedImageError:
        raise ValueError("Attempted to pass an invalid image.")
    image_format = pimage.format.lower()
    if image_format not in current_app.config[KEY_ALLOWED_EXTENSIONS]:
        raise ValueError(f"Attempted to pass invalid data type: {image_format}")
    image_buf.seek(0)
    date_taken = get_date_taken(pimage)
    if date_taken:
        date_taken = datetime.datetime.strptime(date_taken, "%Y:%m:%d %H:%M:%S")
    pimage.getexif().clear()
    scrubbed_image_buf = BytesIO()
    pimage.save(scrubbed_image_buf, image_format)
    pimage.close()
    scrubbed_image_buf.seek(0)
    image_data = scrubbed_image_buf.read()
    hash_img = compute_hash(image_data)
    existing_image = Image.query.filter_by(hash_img=hash_img).first()
    if existing_image:
        return existing_image
    try:
        new_filename = f"{hash_img}.{image_format}"
        scrubbed_image_buf.seek(0)
        url = upload_file_to_s3(scrubbed_image_buf, new_filename)
        new_image = Image(
            filepath=url,
            hash_img=hash_img,
            created_at=datetime.datetime.now(),
            department_id=department_id,
            taken_at=date_taken,
            created_by=user_id,
        )
        db.session.add(new_image)
        db.session.commit()
        return new_image
    except ClientError:
        exception_type, value, full_traceback = sys.exc_info()
        error_str = " ".join([str(exception_type), str(value), format_exc()])
        current_app.logger.error(f"Error uploading to S3: {error_str}")
        return None