I'm trying to add a logged in user ID (wordpress) to a GD image.
When I use a constant it displays the png correctly, when calling a variable it shows a broken image link.
The call is done through a shortcode calling:
/* ================== GET PIC USER ================== */
function get_pic_user($atts) {
$myphp_folder = get_stylesheet_directory_uri() . '/make-pic.php';
$html = '<img src="'.$myphp_folder.'" alt="Image created by a PHP script" width="1000" height="768" align="middle">';
return $html;
}
add_shortcode( 'display_get_pic_user', 'get_pic_user' );
The php behind the make-pic.php is:
<?php
$user = wp_get_current_user();
$string_user = $user->id;
$im = imagecreatefrompng("../my_user_pic.png");
header("Content-type: image/png");
$color = imagecolorallocate($im, 51, 51, 51);
imagestring($im, 21, 500, 350, $string_user, $color);
imagepng($im);
imagedestroy($im);
exit;
So this works:
<?php
$string_user = 15;
$im = imagecreatefrompng("../my_user_pic.png");
and this doesn't:
<?php
$user = wp_get_current_user();
$string_user = $user->id;
$im = imagecreatefrompng("../my_user_pic.png");
Any suggestions would be appreciated.
Thank you