app/Dorcas/Support/helpers.php
/**
 * Converts an image at the specified path/url to a base64-encoded version.
 *
 * @param string $url   URL or path of the image file.
 *
 * @return null|string
 */
Converts an image at the specified path/url to a base64-encoded version.
@param string $url   URL or path of the image file.

@return null|string
Converts an image at the specified path / url to a base64 - encoded version . @param string $url URL or path of the image file . @return null|string
function image_to_base64(string $url)
{
    $specialFiles = ['svg' => 'svg+xml'];
    $type = pathinfo($url, PATHINFO_EXTENSION);
    $type = !array_key_exists($type, $specialFiles) ? $type : $specialFiles[$type];
    $encoded = 'data:image/'.$type.';base64,';
    if (($rawContent = file_get_contents($url)) === false) {
        return null;
    }
    return $encoded . base64_encode($rawContent);
}
function image_to_base64 ( string $ url ) { $ specialFiles = [ 'svg' => 'svg+xml' ] ; $ type = pathinfo ( $ url , PATHINFO_EXTENSION ) ; $ type = ! array_key_exists ( $ type , $ specialFiles ) ? $ type : $ specialFiles [ $ type ] ; $ encoded = 'data:image/' . $ type . ';base64,' ; if ( ( $ rawContent = file_get_contents ( $ url ) ) === false ) { return null ; } return $ encoded . base64_encode ( $ rawContent ) ; }
Converts an image at the specified path/url to a base64-encoded version.
Converts an image at the specified path / url to a base64 - encoded version .
# an array of special extension to type list # update the type