Skip to main content
3 of 3
deleted 5 characters in body
function replaceImageMeta( $imagename ) {

    preg_match_all('/(alt|title|src)=("[^"]*")/i',$imagename, $img);//var_dump( str_replace("\"", "" , ( $img[2][0] ) ) );

    list($width, $height, $type, $attr) = getimagesize( str_replace("\"", "" , ( $img[2][0] ) ));

    $imgname = str_replace("\"", "" , ( $img[2][0] ) );

    return sprintf('<img src="%s" width="%dpx" height="%dpx" >', str_replace("\"", "" , ( $img[2][0] ) ), $width, $height);

}

So call the function with image string

replaceImageMeta( "<img src=\"https://link.to/sum/img.jpg\" alt=\"Image Title\" >" )