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.
19 Related pages
- About PHP
- php Convert Bytes To KB, MB, GB
- PHP date and time
- php define path to dir
- PHP display all images from a folder
- PHP get image as function
- php image upload
- php image width and height
- PHP list all files in directory and subdirectories
- PHP list all image with info
- php list files as array
- php list files with similar name regardless of file extension
- php search for file by name without file extension
- PHP send and catch data
- php strip tags
- php url full path
- php, list all file and folder from dir without file extension
- PHP, SQL, insert from HTML input
- WordPress page conditions front page