ZaZaKi, a web developer Between Manchester UK & Rotterdam NL. © 2015-2024.

PHP get image as function

 


function get_logo($logo){
  $imagePath = "img/logos/$logo.png";
  $img = file_get_contents($imagePath);
  $data = base64_encode($img);
  echo "data:image/png;base64,". $data;
}

Call the function

<img src="<?php get_logo("html"); ?>"/>

Give only the image name into the called function (“only image name here”)
Note: this function only works for png image type change image type for other image type.

Categroy:
back-end , PHP