You can write a function to grab the featured image by post’s ID, then manipulate it and return it as whatever format you wish.
function covert_thumbnail_to_base64($post->ID){
// Get the thumbnail's URL
$thumbnail = get_the_post_thumbnail_url( $post->ID,'thumbnail' );
// Now, process it the way you want
// Return the processed image
return $data;
}
Now you can convert the post’s thumbnail to base64 by calling covert_thumbnail_to_base64();
. if you use this inside a loop, you don’t have to pass the post’s ID to the function. Otherwise, you should feed the function with a post ID.
If you need the absolute path to the image, you can use get_attached_file()
in conjunction with get_post_thumbnail_id()
:
$file_path = get_attached_file( get_post_thumbnail_id($post->ID));