Jump to content

programming images


Recommended Posts

You can create images in virtually any language you care to choose. Web-based images are commonly created using PHP as Capn points out since it's a fairly popular language. However, it's perfectly feasible to create images using C, C++, Perl, Python, or any other language that you care to choose. Chances are that there's an image library for the language that you choose; it's just a matter of finding it. Even if there isn't, it's really trivial to create uncompressed images just by using basic file operations.

Link to comment
Share on other sites

I fiddled around w/ PHP's method of doing it. They have functions at php.net (I think it is). You used to need an extra package beyond PHP and apache. Like mod_php-gtkGD or something. I think after version 5 it comes default though. When you use a package manager for php (5) you see libjpg, libpng, etc in the dependencies list.


Images work just like any other file.


header("Content-type: image/png");

$signature = imagecreatefrompng("mybooringimage.png");

Do some text coloring and,



Something like that. Look it up, it's really not as dificult as you may think.

Link to comment
Share on other sites

Well, those types of images are quite interesting. its quite simple, called a one way door - it allows information from the browser to be sent back but not other information.


If you use PHP you have some powerful functions at your disposal, a friend and I recently finished a quick project that turns images to ASCII art here:




The function was quite simple read the x and y direction, grab the pixel colour and then assign that through CSS.


function ASCII($File)
 $Width  = imagesx($File);
 $Height = imagesy($File);
 $RetVal = '';
 for ($i = 0; $i < $Height; $i++)
   for ($j = 0; $j < $Width; $j++)
     $RGB = imagecolorsforindex($File, imagecolorat($File, $j, $i));
     $HexVal = sprintf('%02X%02X%02X', $RGB['red'], $RGB['green'], $RGB['blue']);
     $RetVal .= '<span style="color: #' . $HexVal . ';">#</span>';     
   $RetVal .= '<br />' . "\n";
 return  $RetVal;


Where the parameter is recieved from either:


imagecreatefrompng(File Name Here);

imagecreatefromgif(File Name Here); or...

imagecreatefromjpg(File Name Here); Depending on the file type of the file too be generated.


As with the generator above, the dynamic images are usually done with PHP although CGI can be used with a little more work :)


As for exactly how the PHP functions themselves work with images, I'm still researching in the source code :)




Ryan Jones

Link to comment
Share on other sites

  • 10 months later...

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.