Factory set on my phone

I have a Samsung s9 and it's been acting stupid the last couple days and I want to do a factory reset but I have a ton of pictures and really don't want to loose them, anyone know how I can reset my phone and not lose anything?