Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7434925
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T09:58:21+00:00 2026-05-29T09:58:21+00:00

Am working on a site which allows users to participate in polls and earn

  • 0

Am working on a site which allows users to participate in polls and earn some points. I’d like them to be able to display their username + score + some other stuff on any website, for example their own blog, forum signatures, etc. as an image. Kindof like stackoverflow flair !

Ofcourse, since their scores and other data will keep changing, I’d like the image to be generated dynamically (I am using php). I have got to a point using canvas where the canvas-png image displays fine on my site, but if I try to use the page url as a src in an img tag, the image doesnot show up.

Below is the page which generates the canvas :

<html>
<head>
<script type="text/javascript" src="/jscripts/jquery.js"></script>
<script type="text/javascript">

$(document).ready(function()
{
    var canvas = document.getElementById("c"),
    context = canvas.getContext("2d");

    context.fillStyle = "rgb(155, 155, 155)";
    context.fillRect(0, 0, 250, 100);
    context.stroke();

    var imgObj = new Image();
    imgObj.onload = function ()
    {            
        // Draw the image on the canvas
        context.drawImage(imgObj, 4, 8, 32, 32);
    }
    imgObj.src="<?=$iUser->avatar?>";

    var username = "Username from php";
    context.fillStyle = "rgb(0, 0, 0)";
    context.font = "18px sans-serif";
    context.fillText(username, 42, 20);

    var score = "CGH Score : " + "146";
    context.fillStyle = "rgb(0, 0, 0)";
    context.font = "14px sans-serif";
    context.fillText(score, 42, 40);


    var img_data=canvas.toDataURL('image/png');
    var img_element="<img src=\"" + img_data + "\" />";
    $("#c").remove();
    $("head").html("<meta http-equiv=\"content-type\" content=\"image/png\"/>");
    $("body").html(img_element);

    //document.body="<img src=\"" + img_data + "\" />";

    //document.write(img_data);
    //var output=img_data.replace(/^data:image\/(png|jpg);base64,/, "");
    //$.post("/show_img/",{image_data:output});


    //window.location = canvas.toDataURL('image/png');
});
</script>

</head>

<body>

<canvas id="c"></canvas>

</body>

</html>
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-29T09:58:22+00:00Added an answer on May 29, 2026 at 9:58 am

    If you load that into an image tag, the browser will NOT interpret/execute the JS. it’ll try to figure what kind of binary image format (gif/jpg/png/etc…) the raw bytes of that page’s source are, and fail. Img tags are not a way to load a remote page/code into a page.

    For this to work, you’d need to have the users insert a snippet of JS which loads the script dynamically from your site.

    e.g. instead of

    <img src="http://yoursite.com/canvas.php" />
    

    you’d have

    <script src="http://yoursite.com/canvas.php" /></script>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm working on an ASP.Net site which allows users to link documents using a
I am working on a site which has some Norwegian words. When I used
I'm working on a site which uses the Facebook API to log users in,
I'm working on a site in which users can opt-in for email notifications for
The Setup: I'm working on a Django application which allows users to create an
I have a working code which allows users to insert url's into a database,
I'm working in a site to manage my company users. Basically it allows login,
I am working an e-commerce site which will allow pdfs to be downloaded once
I have Drupal 7 site which is working fine. I added a custom PHP
I'm currently working on an intracompany web site which will be viewed on cell

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.