number_string    version 0.3    Turn a number into a string, for example turn 11 to "eleven".
There are no comments yet
New Comment
number_string    version 0.3    Turn a number into a string, for example turn 11 to "eleven".
There are no comments yet
New Comment
function pixelate ($image, $blocksize
{
// Based on http://www.tuxradar.com/practicalphp/11/2/24
$imagex = imagesx$image);
$imagey = imagesy$image);
$image2 = imagecreatetruecolor$imagex, $imagey);
imagesavealpha$image2, true);
imagealphablending$image2, false);
if ($blocksize<1) {
$blocksize = 1;
}
for ($x = 0; $x < $imagex; $x += $blocksize) {
for ($y = 0; $y < $imagey; $y += $blocksize) {
// get the pixel colour at the top-left of the square
$colour = imagecolorat$image, $x, $y);
// set the new red, green, blue and alpha values to 0
$newr = 0;
$newg = 0;
$newb = 0;
$newt = 0;
// create an empty array for the colours
$colours = array();
// cycle through each pixel in the block
for ($k = $x; $k < $x + $blocksize; ++$k) {
for ($l = $y; $l < $y + $blocksize; ++$l) {
// if we are outside the valid bounds of the image, use a safe colour
if ($k < 0) { $colours[] = $colour; continue; }
if ($k >= $imagex) { $colours[] = $colour; continue; }
if ($l < 0) { $colours[] = $colour; continue; }
if ($l >= $imagey) { $colours[] = $colour; continue; }
// if not outside the image bounds, get the colour at this pixel
$colours[] = imagecolorat$image, $k, $l);
}
}
// cycle through all the colours we can use for sampling
foreach$colours as $colour) {
$colour = imagecolorsforindex$image, $colour);
// add their red, green, and blue values to our master numbers
$newr += $colour'red'];
$newg += $colour'green'];
$newb += $colour'blue'];
$newt += $colour'alpha'];
}
// now divide the master numbers by the number of valid samples to get an average
$numelements = count$colours);
$newr /= $numelements
$newg /= $numelements
$newb /= $numelements
$newt /= $numelements
// and use the new numbers as our colour
$newcol = imagecolorallocatealpha$image2, $newr, $newg, $newb, $newt);
imagefilledrectangle$image2, $x, $y, $x + $blocksize - 1, $y + $blocksize - 1, $newcol);
}
}
return $image2
}
function quick_sort ($array
{
if (count$array)<=1) {
return $array
} else {
$pivot = $array[0];
$lesser = array();
$greater = array();
for ($i=1;$icount$array);$i++) {
if ($array$i]<=$pivot) {
$lesser[] = $array$i];
} else {
$greater[] = $array$i];
}
}
return array_mergequick_sort$lesser), array$pivot), quick_sort$greater));
}
}
function tag_cloud ($tags, $min_size, $max_size, $link, $link_class
{
$min = minarray_values$tags));
$max = maxarray_values$tags));
$spread = $max - $min
$cloud = ''
if ($link_class != '') $link_class = "class="$link_class" "
if ($spread == 0) $spread = 1;
foreach$tags as $tag => $count) {
$size = $min_size + ($count - $min) * ($max_size - $min_size) / $spread
$cloud .= '<a style="font-size:'floor$size).'px" '$link_class
.'href="'$linkurlencode$tag).'">'$tag"</a>n"
}
return $cloud
}
This page will help you embed the algorithm show_address on a page on your own website. Just configure the inputs, then click the generate button to get a snippet of code you can paste onto your site. You have two options.
function lcm ($a, $b
{
return abs$a$b)/gcd_euclid$a, $b);
}
function random_name_caption ($image, $your_name
{
$sizey = imagesy$image);
$sizex = imagesx$image);
if (mt_rand(0,1)==1)
$color = imagecolorallocate$image, 254, 0, 0);
else
$color = imagecolorallocate$image, 0, 0, 254);
$y = mt_rand(0,$sizey-10);
$x = mt_rand(0,$sizex-10);
imagestring$image, 4, $x, $y, $your_name, $color);
$return = array
'return' => $image
'arguments' => array$image, $your_name
);
return $return
}
function next_prime ($start
{
$primes = -1;
for$i = $start+1; ; $i++)
{
$is_prime = true;
for$j = 2; $j < floor$i/2); $j++)
{
if(($i % $j) == 0)
{
$is_prime = false;
break
}
}
if ($is_prime
{
$prime = $i
break
}
}
return $prime
}
function bogosort ($array
{
while (!sorted$array)) {
shuffle$array);
}
return $array
}