Last active
January 20, 2021 14:09
-
-
Save ravahdati/2149b3358dbf907e2fa4118c1485dd43 to your computer and use it in GitHub Desktop.
Revisions
-
ravahdati revised this gist
Nov 13, 2020 . 1 changed file with 1 addition and 0 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,3 +1,4 @@ <?php function tidaweb_image_url_to_base64( $attach_id ) { // get image src -> $image_info[0] -
ravahdati created this gist
Nov 13, 2020 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,12 @@ function tidaweb_image_url_to_base64( $attach_id ) { // get image src -> $image_info[0] $image_info = wp_get_attachment_image_src( $attach_id, 'full' ); $image_file = file_get_contents( $image_info[0] ); // get filename from url $filename = basename( get_attached_file( $attach_id ) ); $image_file_type = wp_check_filetype( $filename ); return 'data:image/'.$image_file_type['ext'].';base64,'.base64_encode( $image_file ); }