It depends what language you are using from a code perspective.
At a high level, you need to upload the image via the media/upload endpoint, check the media ID in the response from that call, and then post a Tweet using statuses/update with the associated media ID.
There’s an example of how you can do this using Python in our samples repository (it is a video example, but can work for images as well).