PHP for art? Some say I am nuts but I think it is fun. Math makes the world go round and most art is built on it.
Maybe you read our previous attempt at dynamically creating LARGE graphics from a tiny thumbnail using only PHP. No Photoshop and no filters. Kinda cool that a middleware built to drive dynamic websites can extend to such a level utilizing only built-in functions. The previous article used the ImageCreateFromJPEG function. Today we are going to show you an example that will use the ImageColorAllocate to set colors and imagelines to draw a dynamic shape.
The goal is to end with a “diamond prism” shape. It uses imagelines to coordinate lines generated by a FOR flow control that will lead into our final shape. We need to set a variable for the image overall size, followed by the colors. That is set with the ImageColorAllocate function mentioned earlier. Finally we have our image imagePng($image). I am not a verbose guy when it comes to explanations. The code is pretty straightforward but I am happy to answer any questions via your comments.
<?php
$width=300;
$height=300;
Header("Content-type: image/gif");
$image = imagecreate($width,$height);
$white=ImageColorAllocate($image,255,255,255);
$green=ImageColorAllocate($image, 0x00, 0xFF, 0x22);
for ($i=0;$i<=150;$i+=10)
{
imageline($image,160-$i,150,160,$i,$green);
imageline($image,160+$i,150,160,$i,$green);
imageline($image,160,160+$i,$i,150,$green);
imageline($image,160,300-$i,160+$i,150,$green);
}
imagePng($image);
ImageDestroy($image);
?>

Stay tuned for upcoming examples. We will be using a TTF (true type font) with the ImageTTFText function to draw a .png dynamically into your page. Great for buttons on the fly! Seriously, it is really cool stuff. Also, we will be building a basic shape with ImageFilledRectangle function and using string text for a caption. Small images on the fly.
Good Luck and Happy Coding,
Z
Tags: Extend, Functions, PHP, Structure, Web Design


Want Something Else?