function encode(data, mediaType) {
        if (!data || !mediaType) {
            log.error("image-data-uri", "Missing some of the required params: data, mediaType");
            return null;
        }

        mediaType = (/\//.test(mediaType)) ? mediaType : "image/" + mediaType;
        let dataBase64 = (Buffer.isBuffer(data)) ? data.toString("base64") : new Buffer(data).toString("base64");
        let dataImgBase64 = "data:" + mediaType + ";base64," + dataBase64;

        return dataImgBase64;
    }
Endcode an image into data:image/ URI
@param {(Buffer|string)} data Data to encode
@param {string} mediaType Media type of data
@returns {(string|null)} A string representing the base64-encoded
version of the given Buffer object or null if an error occurred.