PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!
Everah | Please use the correct bbCode tags when posting code in the forums. You can use [code], [php], [{lang}] or [syntax="{lang}"] where {lang} is the lowercase string name of the language you want to parse.
Hi, I have used this code below for my flash animation. The flash is linked to the php coding below. Flash captures the image when the button is clicked and passes it to the php script to display the on to a internet broswer. I just need any help commenting this coding. Thanks:
Everah | Please use the correct bbCode tags when posting code in the forums. You can use [code], [php], [{lang}] or [syntax="{lang}"] where {lang} is the lowercase string name of the language you want to parse.
If you wrote this code yourself you shouldn't have any problem commenting it. If you didn't write it then this is a great opportunity for you to learn something new about php. Try going to the documentation on php.net
i did not rite the code myself...so i found it on the web and applied to my application and it worked. I just dont know what the coding means. IF you could comment on partial of the code id be glad
<?php
/**
* Capture the form field 'img' and split it on a comma
*
* Things to look out for:
* - This never checks for a posted form
* - Soooo, this could throw errors if coming directly into this page
*/
$data = explode(",", $_POST['img']);
/**
* These are setting the width and height variables from the information in the form
*
* Things to look out for:
* - Again, these form fields are not ever checked so they could very well throw an error
*/
$width = $_POST['width'];
$height = $_POST['height'];
/**
* This creates a new image resource handle for an image with the passed arguments
* as the dimensions.
*
* Things to look out for:
* - If there is not form this will puke all over the place.
*/
$image=imagecreatetruecolor( $width ,$height );
/**
* This sets the images background color - apparently to black
*/
$background = imagecolorallocate( $image ,0 , 0 , 0 );
/**
* This copies pixels, pixel by pixel, from the $data variable
*
* There is some magic happening here, keep a close eye...
*/
$i = 0;
for ($x = 0; $x <= $width; $x++) {
for ($y = 0; $y <= $height; $y++) {
// Set up the hexidecimal value of of $ith value incrementing $i in the process
$int = hexdec($data[$i++]);
// Sets a color into the image resource, the colors being created by bitwise value checking of the $int var
$color = ImageColorAllocate ($image, 0xFF & ($int >> 0x10), 0xFF & ($int >> 0x8), 0xFF & $int);
// Set the pixel into the image resource
imagesetpixel ( $image , $x , $y , $color );
}
}
/**
* Set the appropriate output header to let the user agent know what to do with it.
*/
header( "Content-type: image/jpeg" );
/**
* Send the image to the user
*/
ImageJPEG( $image );
/**
* Free up the image resouce
*/
imagedestroy( $image );
?>