You can edit images both programmatically and using other applications. If you optimize the images by code you will anyhow have to store it in the app thus increasing the size of the application so it is better to optimize and then add it to the project.
As easy to use website to optimize images is https://tinypng.com/