PHP was not working for me as I was encountering this libpng issue, so I reinstalled a new version with Homebrew.
However, I\'m getting a similar error with
Homebrew php has been updated and no longer an issue with libjpeg
I didn't try Jirson's answer, but what worked for me was:
brew uninstall libjpeg
brew install libjpeg
In some cases, especially in Catalina, the Homebrew cask for the package may exist but not be properly linked. In that case try:
brew link libjpeg
brew reinstall php --build-from-source