Obfuscated Cake

Almost forgot about this one. I wrote it back in June 2008 for Jeremy’s birthday since he was having a rough day. Like the heart, this is code in the shape of a birthday cake (well, as long as you use some imagination :-P ) that draws a birthday cake. A chocolate one.

The code first draws the main cake rectangle. After that, it loops three times to draw the rectangles for the candlesticks, polygons for the flames, then orange circles with an alpha channel for the light. It finishes off with a series of lines whose lengths are determined by the sine function, used for the frosting.

Here’s the output.

<?php               header             ('Content'.
'-type:'.          'image/png'         );$f = 'im'.
'agecre'.          'atetrueco'.        'lor';$im=$f
(250,250);         $g='imagef'.        'illedrect'.
'angle';$g         ($im,10,120,        240,240,(630*
10000)+ 37         *100+44);for        ($i=0;$i<3;$i
++){$x=60+         $i*60;$g($im        ,$x+2,50,$x+8,
120,0xeeeeee);$h=str_rot13('vzntrsvyyrqcbyltba');$h(
$im,array($x,50,$x+5,30,$x+10,50),3,0xc00000);$h($im,
array($x+2,50,$x+ 5,40,$x+8,50),3, 0xff8000);$h ($im,
array($x+3,50,$x+5,45,$x+7,50),3,0x0000ff);$el='ima'.
'gefilledellipse';$el($im,$x+5,40,40,40,0x48ffa000);}
$l='i'.'m'.'a'. 'g'.'e'.'l'.'in'.'e';$c=0xd0d0ff; for
($i=10;$i<=240;$i++){$y=130+3* sin(($i-10)/2);$l($im,
$i,120,$i,$y,$c);}$p=strrev('egami').'png';$d='imag';
$d.='ede';$de='str';$d.=$de;$d.='oy';$p($im);$d($im);

Unobfuscated version:

<?php

header('Content-type: image/png');
$img = imageCreateTrueColor(250, 250);
imageFilledRectangle($img, 10, 120, 240, 240, 0x603000);

// loop through the 3 candles
for ($i = 0; $i < 3; $i++) {
	$x = 60 + $i * 60;
	// candlestick, red flame, orange flame, blue flame, light
	imageFilledRectangle($img, $x + 2, 50, $x + 8, 120, 0xEEEEEE);
	imageFilledPolygon($img, array($x, 50, $x + 5, 30, $x + 10, 50), 3, 0xC00000);
	imageFilledPolygon($img, array($x + 2, 50, $x + 5, 40, $x + 8, 50), 3, 0xFF8000);
	imageFilledPolygon($img, array($x + 3, 50, $x + 5, 45, $x + 7, 50), 3, 0x0000FF);
	imageFilledEllipse($img, $x + 5, 40, 40, 40, 0x48FFA000);
}

// frosting
for ($i = 10; $i <= 240; $i++) {
	$y = 130 + 3 * sin(($i - 10) / 2);
	imageLine($img, $i, 120, $i, $y, 0xD0D0FF);
}

imagePNG($img);
imageDestroy($img);
This entry was posted in PHP and tagged , . Bookmark the permalink.

One Response to Obfuscated Cake

  1. Pingback: Canvas Cake | Steve's Blog

Leave a Reply

Your email address will not be published. Required fields are marked *

*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>