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

  • SEARCH
  • Home
  • 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 7176707
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T16:33:50+00:00 2026-05-28T16:33:50+00:00

I have a class with several functions that can render images. // render.php class

  • 0

I have a class with several functions that can render images.

// render.php
class Render {
   public function Render($some_arguments) {
      ...
      header("Content-Type: image/png");
        $im = @imagecreate(110, 20)
            or die("Cannot Initialize new GD image stream");
        $background_color = imagecolorallocate($im, 0, 0, 0);
        $text_color = imagecolorallocate($im, 233, 14, 91);
        imagestring($im, 1, 5, 5,  "A Simple Text String", $text_color);
        imagepng($im);
        return "data:image/png;base64,".base64_encode($im);
   }
}

Then I have my php file that contains the html code and where I would like to output the image within an < img> tag:

// index.php
include("render.php");
$render = new Render();
echo "<htlm><head></head><body>";
echo "<img src=\"".$render->Render(1)."\" />";
echo "</body></html>";

When I run index.php in my browser I just get a blank screen.

Can´t I use a function call as an image source? I know I can use a php file as source, like < img src="render_image.php" />, but then I cannot send any arguments in an object oriented manner (I know I can use $_GET to retrieve arguments), but I would like to do it with a nice object oriented written code.

So, is there any way to use a function call as a source of a html tag?

  • 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-28T16:33:51+00:00Added an answer on May 28, 2026 at 4:33 pm

    You’ll have to split it:

    Render(...) will write a temporary file (with a randomized name), that is accessible from the web for some time.

    A new method Output() will return the randomized name mentioned above.

    You then call Render() before outputting the HTML and embed the URL using Output().

    As an alternative, you could use some file or database to exchange the parameters, essentially some method Prepare(...)? writing the params to the file or database, and Render() reading those and placing the file again etc.

    As yet another alternative (without writing to the file system): You could implement include the image data using a data: uri, but the image size will be limited depending on the browser used and you can’t cache the data this way (i.e. you have to send it all the time).

    Depending on what you’re trying to achieve, you might have luck embedding a SVG image as well. This would offer the huge advantage of being in-place while still using less bandwith, being scalable, etc. Downside is, this is only supported in newest browsers (similar to data:) but there are no size restrictions.


    Edit: Using the base64/embedded approach it get’s a bit more tricky resulting in something like this (untested, but should work):

    ob_start(); // buffers future output
    imagepng($img); // writes to output/buffer
    $b64 = base64_encode(ob_get_contents()); // returns output
    ob_end_clean(); // clears buffered output
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a Binary-Tree class template with several public and private member functions. When
I have a class that contains a private typedef and several member functions: class
I have a class that holds several vectors of objects: struct ComponentA { public:
We have some code that looks like this: class Serializer { public: template<class Type>
I have a class that creates several IDisposable objects, all of these objects are
I have a class Person which can have several Homes, each one with one
I have a class that currently has several methods that take integer parameters. These
I have a class that is called regularly by several objects. I would like
I have a class TContainer that is an aggregate of several stl collections pointers
following setup, i have several generic functions, and i need to choose the type

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.