We need to understand what is the use cases for this function and what is the benefit of implementing it.

PROs: (and use cases)

To show many small images (thumbnails or emoticons or others) in 1 page,
sometimes better to save the images in a database and then display them in HTML using this embedded base64 encoded text data method
to avoid too many image request connections from browser to image server or CDN.

If using web page which has JS script to wait for loading many images then using this logic will reduce JS waiting time

To prevent a direct connection from a browser or curl command to get the image files,
this way will also ensure to display a landing webpage instead of giving the image data immediately.

To create image viewing counter logic, to know which images are most viewed.

To avoid many file operations to delete or update if the images are often updated, such as product thumbnails, profile avatar, etc.

For small project with limited capacity issue, we can store the image as base64 encoded text to different 'free' hosting and create an API to get the image, this is to create a 'free' CDN.

CONs:

The web page may have long base64 text and page source size will be bigger.

Browser may not be able to keep the image data in cache or if cached there is no way to tell 'expire' time.

To avoid the 'CONs' described above, we can create an API in server to return the image, using PHP is as simple as: