I had a similar problem on a couple of localhosts I was playing around with in the last two days. My images were replaced with their alternative text. There probably are much better solutions.
My solution: I noticed that when I took a backup from another Moodle and then did a restore of a course (deleted old and replaced an existing course) on my troublesome Moodle, Moodle got the right path and there were the images. That was taking a 1.54 backup and restoring it on a 1.63 and on a 1.7x Moodle, but I suspect it worked because each moodle was at a different location.
How I created the problem: I changed my Moodle\config.php file from the $CFG->
wwwroot = localhost = a fix IP assigned to a computer. I also changed the
Apache\config\httpd.conf file around line 170 that said ServerName localhost:80 to the fixed IP:80. What did not work was all my pictures in my lessons still pointed to http://localhost/file.php/4/Images_Prevention_and_Recognition/img0. jpg
instead of showing the fixed IP in something like http: //123.45.12.3/.... I would just see the alternative text, no image. All the file were in the right place.
It did not work when I backup up the course on the same Moodle and then tried the restore trick. I tried changing the moodle/config.php $CFG->dbhost = 'localhost'; to a fixed IP but it did not like that at all
Chris