Skip to content

Instantly share code, notes, and snippets.

@RyujiAMANO
Created December 14, 2015 23:59
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save RyujiAMANO/34d62e77afa0b9281675 to your computer and use it in GitHub Desktop.
Save RyujiAMANO/34d62e77afa0b9281675 to your computer and use it in GitHub Desktop.
<?php
function smarty_modifier_inline_image($url)
{
// $urlを内部パスに置き換える
$path = str_replace(XOOPS_URL , XOOPS_ROOT_PATH, $url);
if(strpos($path, XOOPS_ROOT_PATH) === false){
// 内部パスに置き換えられなければ元のURLを返す
return $url;
}
$img = base64_encode(file_get_contents($path));
$finfo = finfo_open(FILEINFO_MIME);
$mime = finfo_file($finfo, $path);
$src = 'data:' . $mime. ';base64,'.$img;
return $src;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment