How to add WP variables to GD imagepng












1















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










share|improve this question

























  • 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 '18 at 20:03


















1















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










share|improve this question

























  • 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 '18 at 20:03
















1












1








1








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










share|improve this question
















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






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 19 '18 at 16:47







Duttch

















asked Nov 19 '18 at 16:25









DuttchDuttch

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 '18 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 '18 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 '18 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 '18 at 20:03














1 Answer
1






active

oldest

votes


















0














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' );





share|improve this answer

























    Your Answer






    StackExchange.ifUsing("editor", function () {
    StackExchange.using("externalEditor", function () {
    StackExchange.using("snippets", function () {
    StackExchange.snippets.init();
    });
    });
    }, "code-snippets");

    StackExchange.ready(function() {
    var channelOptions = {
    tags: "".split(" "),
    id: "1"
    };
    initTagRenderer("".split(" "), "".split(" "), channelOptions);

    StackExchange.using("externalEditor", function() {
    // Have to fire editor after snippets, if snippets enabled
    if (StackExchange.settings.snippets.snippetsEnabled) {
    StackExchange.using("snippets", function() {
    createEditor();
    });
    }
    else {
    createEditor();
    }
    });

    function createEditor() {
    StackExchange.prepareEditor({
    heartbeatType: 'answer',
    autoActivateHeartbeat: false,
    convertImagesToLinks: true,
    noModals: true,
    showLowRepImageUploadWarning: true,
    reputationToPostImages: 10,
    bindNavPrevention: true,
    postfix: "",
    imageUploader: {
    brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
    contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
    allowUrls: true
    },
    onDemand: true,
    discardSelector: ".discard-answer"
    ,immediatelyShowMarkdownHelp:true
    });


    }
    });














    draft saved

    draft discarded


















    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

























    1 Answer
    1






    active

    oldest

    votes








    1 Answer
    1






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes









    0














    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' );





    share|improve this answer






























      0














      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' );





      share|improve this answer




























        0












        0








        0







        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' );





        share|improve this answer















        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' );






        share|improve this answer














        share|improve this answer



        share|improve this answer








        edited Nov 21 '18 at 19:05

























        answered Nov 21 '18 at 17:17









        DuttchDuttch

        113




        113






























            draft saved

            draft discarded




















































            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.




            draft saved


            draft discarded














            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





















































            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







            Popular posts from this blog

            Guess what letter conforming each word

            Port of Spain

            Run scheduled task as local user group (not BUILTIN)