How to add WP variables to GD imagepng
up vote
1
down vote
favorite
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
php wordpress gd php-gd
add a comment |
up vote
1
down vote
favorite
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
php wordpress gd php-gd
On debugging the issue further, I've notice the following: Its giving a FATAL ERROR: Uncaught Error: Call to undefined function wp_get_curent_user() in .....
– Duttch
Nov 20 at 20:03
add a comment |
up vote
1
down vote
favorite
up vote
1
down vote
favorite
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
php wordpress gd php-gd
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
php wordpress gd php-gd
php wordpress gd php-gd
edited Nov 19 at 16:47
asked Nov 19 at 16:25
Duttch
113
113
On debugging the issue further, I've notice the following: Its giving a FATAL ERROR: Uncaught Error: Call to undefined function wp_get_curent_user() in .....
– Duttch
Nov 20 at 20:03
add a comment |
On debugging the issue further, I've notice the following: Its giving a FATAL ERROR: Uncaught Error: Call to undefined function wp_get_curent_user() in .....
– Duttch
Nov 20 at 20:03
On debugging the issue further, I've notice the following: Its giving a FATAL ERROR: Uncaught Error: Call to undefined function wp_get_curent_user() in .....
– Duttch
Nov 20 at 20:03
On debugging the issue further, I've notice the following: Its giving a FATAL ERROR: Uncaught Error: Call to undefined function wp_get_curent_user() in .....
– Duttch
Nov 20 at 20:03
add a comment |
1 Answer
1
active
oldest
votes
up vote
0
down vote
accepted
After adding several REQUIRE and other solutions issues still manifested. A working solution that I came up with was to add the IMAGEPNG just inline with code, however using a OB_START / OB_GET_CLEAN. The following works:
The image is still called from the page with a shortcode [display_get_pic_user]. The code behind it is:
function get_pic_user() {
$user = wp_get_current_user();
$string_user = $user->id;
$im = imagecreatefrompng("../my_user_pic.png");
$color = imagecolorallocate($im, 51, 51, 51);
imagestring($im, 21, 500, 350, $string_user, $color);
ob_start();
imagepng($im);
$rawImageBytes = ob_get_clean();
$html = "<img src='data:image/png;base64," . base64_encode( $rawImageBytes ) . "' align=middle/>";
imagedestroy($im);
return $html;
}
add_shortcode( 'display_get_pic_user', 'get_pic_user' );
add a comment |
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
0
down vote
accepted
After adding several REQUIRE and other solutions issues still manifested. A working solution that I came up with was to add the IMAGEPNG just inline with code, however using a OB_START / OB_GET_CLEAN. The following works:
The image is still called from the page with a shortcode [display_get_pic_user]. The code behind it is:
function get_pic_user() {
$user = wp_get_current_user();
$string_user = $user->id;
$im = imagecreatefrompng("../my_user_pic.png");
$color = imagecolorallocate($im, 51, 51, 51);
imagestring($im, 21, 500, 350, $string_user, $color);
ob_start();
imagepng($im);
$rawImageBytes = ob_get_clean();
$html = "<img src='data:image/png;base64," . base64_encode( $rawImageBytes ) . "' align=middle/>";
imagedestroy($im);
return $html;
}
add_shortcode( 'display_get_pic_user', 'get_pic_user' );
add a comment |
up vote
0
down vote
accepted
After adding several REQUIRE and other solutions issues still manifested. A working solution that I came up with was to add the IMAGEPNG just inline with code, however using a OB_START / OB_GET_CLEAN. The following works:
The image is still called from the page with a shortcode [display_get_pic_user]. The code behind it is:
function get_pic_user() {
$user = wp_get_current_user();
$string_user = $user->id;
$im = imagecreatefrompng("../my_user_pic.png");
$color = imagecolorallocate($im, 51, 51, 51);
imagestring($im, 21, 500, 350, $string_user, $color);
ob_start();
imagepng($im);
$rawImageBytes = ob_get_clean();
$html = "<img src='data:image/png;base64," . base64_encode( $rawImageBytes ) . "' align=middle/>";
imagedestroy($im);
return $html;
}
add_shortcode( 'display_get_pic_user', 'get_pic_user' );
add a comment |
up vote
0
down vote
accepted
up vote
0
down vote
accepted
After adding several REQUIRE and other solutions issues still manifested. A working solution that I came up with was to add the IMAGEPNG just inline with code, however using a OB_START / OB_GET_CLEAN. The following works:
The image is still called from the page with a shortcode [display_get_pic_user]. The code behind it is:
function get_pic_user() {
$user = wp_get_current_user();
$string_user = $user->id;
$im = imagecreatefrompng("../my_user_pic.png");
$color = imagecolorallocate($im, 51, 51, 51);
imagestring($im, 21, 500, 350, $string_user, $color);
ob_start();
imagepng($im);
$rawImageBytes = ob_get_clean();
$html = "<img src='data:image/png;base64," . base64_encode( $rawImageBytes ) . "' align=middle/>";
imagedestroy($im);
return $html;
}
add_shortcode( 'display_get_pic_user', 'get_pic_user' );
After adding several REQUIRE and other solutions issues still manifested. A working solution that I came up with was to add the IMAGEPNG just inline with code, however using a OB_START / OB_GET_CLEAN. The following works:
The image is still called from the page with a shortcode [display_get_pic_user]. The code behind it is:
function get_pic_user() {
$user = wp_get_current_user();
$string_user = $user->id;
$im = imagecreatefrompng("../my_user_pic.png");
$color = imagecolorallocate($im, 51, 51, 51);
imagestring($im, 21, 500, 350, $string_user, $color);
ob_start();
imagepng($im);
$rawImageBytes = ob_get_clean();
$html = "<img src='data:image/png;base64," . base64_encode( $rawImageBytes ) . "' align=middle/>";
imagedestroy($im);
return $html;
}
add_shortcode( 'display_get_pic_user', 'get_pic_user' );
edited Nov 21 at 19:05
answered Nov 21 at 17:17
Duttch
113
113
add a comment |
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Some of your past answers have not been well-received, and you're in danger of being blocked from answering.
Please pay close attention to the following guidance:
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53378874%2fhow-to-add-wp-variables-to-gd-imagepng%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
On debugging the issue further, I've notice the following: Its giving a FATAL ERROR: Uncaught Error: Call to undefined function wp_get_curent_user() in .....
– Duttch
Nov 20 at 20:03