In your sprite’s image files, is the character 's body perfectly centered within each image on the x-axis? If it isn’t centered, then flipping the entire image horizontally will result in it shifting across the center to the other side of the image. I think this is the most likely explanation.
You mean fixing it programmatically, without changing the original image?
That would probably require storing an x-offset for each image to indicate how much to shift it when flipping. And depending whether your character is facing left or right, adding or subtracting that value from the sprite’s x-position. Or if each image is offset by the same amount, storing a single x-offset and using that for all of them.
But either way, it’s adding complexity and effort for no real gain. Counting pixels and storing them for every image.
Centering the original images would require the least effort. Especially when you start adding more objects that can also face both directions.