Skip to content

Instantly share code, notes, and snippets.

Avatar

ravahdati

View GitHub Profile
@ravahdati
ravahdati / upload-base64-image-to-wp.php
Last active Nov 13, 2020
Upload base64 images to wordpress upload directory
View upload-base64-image-to-wp.php
<?php
function tidaweb_upload_base64_image( $base64_image_data, $base64_file_name )
{
// check and get path of upload directory
$upload_dir = wp_upload_dir();
$upload_path = str_replace( '/', DIRECTORY_SEPARATOR, $upload_dir['path'] ) . DIRECTORY_SEPARATOR;
$img = $base64_image_data;
if(strpos($img, 'image/jpg') !== false)
{
@ravahdati
ravahdati / convert-wp-image-to-base64.php
Last active Jan 20, 2021
Convert WordPress image to base64 by attach_id
View convert-wp-image-to-base64.php
<?php
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 );