convert - 在线代码运行


            
执行结果

名称:convert

当前代码

<?php
//$srcfilepath = $argv[1];
//$dstfilepath = $argv[2];
 
$srcfilepath = "C:\Users\u0163190\liutest\UBNe1.htm";
$dstfilepath = "C:\Users\u0163190\liutest\result.html";

$srcDir = dirname($srcfilepath);
$srcName = basename($srcfilepath);
 
// Read the whole template file into memory
if (($template_content = file_get_contents($srcfilepath)) === false) {
   fprintf($stderr, "Unable to read html file: {$srcfilepath}\n");
   return false;
}
 
// Match the IMG tag one at a time
$offset = 0;
$done = 0;
 
while (preg_match("/<img src='\.\/([0-9]*\/data\.png)'\/>/", $template_content, $match, PREG_OFFSET_CAPTURE, $offset) >= 1) {
 
    $matchTag = $match[0][0];
    $matchOffset = $match[0][1];
    $subDirImgFile = $match[1][0];
 
    $chart_pngfile = "{$srcDir}/{$subDirImgFile}";
 
    if (!file_exists($chart_pngfile)) {
       echo "Unable to find png file {$chart_pngfile}\n";
       return;
    }
 
    $img_tag = "<img src='data:image/png;base64," . base64_encode(file_get_contents($chart_pngfile)) . "'/>";
 
    // Replace the IMG src link tag with IMG embed content
    $template_content = substr_replace($template_content, $img_tag, $matchOffset, strlen($matchTag));
 
    // offset for next loop
   $offset = $matchOffset + strlen($img_tag);
 
}
 
file_put_contents($dstfilepath, $template_content);
?>