Geeks around the Z were having a bit of fun today. I am an avid Photoshop and PHP guy and the wife is a writer who enjoys sharing her online adventures. I do my best not to train wreck this web-space with a PHP snafu but it does happen. Some day when you visit and it loads slower than a snail on a piece of rough concrete, you will KNOW I am online.
There is a point to this scenario. In fact, the average geek will find this pretty cool. I tinker with both Photoshop and PHP but I am a master of neither. My question to you, the visitor, what happened today? The chicken or the egg? Photoshop or PHP? Look at the image, was this another overused Photoshop filter? Or was it created with PHP? Can you tell?
UPDATE:
Just in case you missed the other installments of PHP Artwork:
We used the imageline in an article called PHP Artwork. Imageline and a FOR flow control can create some really cool “prisms.” The ImageTTFText installment utilized the built-in PHP function ImageTTFText to build a quick png graphic. Great for Captcha. The latest installment of PHP Artwork on our WordPress blog built a green box using the ImageFilledRectangle function and then added a caption to it using the PHP built-in function called ImageString.
Today while I was creating a few images for Desi’s article and thinking of post tags (we are an exciting bunch)… it kinda hit me. Time to break out of the norm, step away from the WordPress and do something different.
These graphics were dynamically created using PHP. No Photoshop and no filters. Kinda cool that a middleware built to drive dynamic websites can extend to such a level. I borrowed Desi’s NomNom graphic from her online Time Wasters article at 80px wide. Then loaded a snippet of coding and it created a pretty sharp image considering the one up top is using the ASCII # sign to recreate a full-screen colorized version with no distortion. Heck, the lighter image is using the word “cat.” You may not understand coding but a web “middleware” is used to call data from a database (dynamic content) and this same “middleware” created these images? Come on. Yes, it did, It can also output .SWF (Flash) and .PDF files. Thank you ASCII and PHP for bringing such joy. The proof is in the pudding; so here it is, the browser snapshot:
The coding is short and easy to follow for you PHP folk. Give it a try! Believe it or not, this image was 80 pixels wide when PHP scaled it. Just make sure that you have your “resource” graphic in the same directory or fix the path. Be careful or you can put your computer in a bind using a “large” image.
<?php
$cat = ImageCreateFromJPEG('image.jpg');
$dx = ImageSX($cat);
$dy = ImageSY($cat);
for($y=0; $y < $dy; $y++){
for($x=0; $x < $dx; $x++){
$col = ImageColorAt($cat, $x, $y);
$rgb = ImageColorsForIndex($cat, $col);
printf ('<font color=#%02x%02x%02x>CAT</font>',
$rgb['red'], $rgb['green'], $rgb['blue']);
}
echo "<br>\n";
}
ImageDestroy($cat);
?>
Happy Coding,
Z
Tags: Functions, ImageCreateFromJPEG, Photoshop, PHP, WordPress


Want Something Else?