×

Welcome to TagMyCode

Please login or create account to add a snippet.
0
0
 
0
Language: PHP
Posted by: userc865b
Added: Jul 7, 2017 10:55 AM
Views: 6
Tags: php
  1. function getDataUristringFromImagePath($imagePath) {
  2.     $type = pathinfo($imagePath, PATHINFO_EXTENSION);
  3.     $data = file_get_contents($imagePath);
  4.     /** @noinspection PhpUnusedLocalVariableInspection */
  5.     $dataUri = 'data:image/' . $type . ';base64,' . base64_encode($data);
  6.     return $type;
  7. }
  8.  
  9. function getDataUristringImageBarcode($image) {
  10.     $dataUri = base64_encode($image);
  11.     return $dataUri;
  12. }
  13.  
  14. function getDataURI($image, $mime = '') {
  15.     return 'data:' . (function_exists('mime_content_type') ? mime_content_type($image) : $mime) . ';base64,' . base64_encode(file_get_contents($image));
  16. }