Example #1
0
 protected function embedImages(File &$file)
 {
     $loop_breaker = 0;
     $contents = $file->getContents();
     $image_pos = strpos($contents, 'image://');
     while ($image_pos !== false) {
         $loop_breaker++;
         if ($loop_breaker > 200) {
             break;
         }
         $image_end = strpos($contents, ')', $image_pos);
         $file_name = trim(substr($contents, $image_pos + 8, $image_end - ($image_pos + 8)));
         $full_file_name = $this->getImageFullFileName($file_name);
         $image_data = '';
         if (file_exists($full_file_name)) {
             $image_data = base64_encode(file_get_contents($full_file_name));
         }
         $contents = substr($contents, 0, $image_pos) . 'data:image/png;base64,' . $image_data . substr($contents, $image_end);
         $image_pos = strpos($contents, 'image://');
     }
     $file->tempSetContents($contents);
 }