PHP ARTWORK -imageline

About me: I am an everyday Joe Schmoe that enjoys spending way too much time on the internet. Internet technologies such as XHTML, PHP, CSS, and FLASH are my best friends and hobbies. They are daily learning experiences that I enjoy sharing with others.

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

PHP Artwork

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: , , , ,

The Comments

  1. Desiree Zabinsky posted on April 20, 2010 | Permalink

    This is so cool! Can you build a DeathStar with your mad PHP skills? That would be sweet.By the way…what’s a nice guy like you doing in a place like this when there’s a Farscape marathon on right now on the Sci Fi channel? *Geek..snort*

Register!

Flash by Z | The eclectic blogoshpere of Coding, Humor, Design and People


That's it - back to the top of page!

Recent Posts

POPULAR POSTS!