function blend_colors ($color1, $color2, $weight
{
if ($weight<0 || $weight>1)
throw new Exception"Weight must be between 0 and 1");
$r1 = hexdecsubstr$color1, 0, 2));
$g1 = hexdecsubstr$color1, 2, 2));
$b1 = hexdecsubstr$color1, 4, 2));
$r2 = hexdecsubstr$color2, 0, 2));
$g2 = hexdecsubstr$color2, 2, 2));
$b2 = hexdecsubstr$color2, 4, 2));
$r = dechexround$r1$weight + $r2*(1-$weight)));
$g = dechexround$g1$weight + $g2*(1-$weight)));
$b = dechexround$b1$weight + $b2*(1-$weight)));
if (strlen$r)==1) $r = '0'$r
if (strlen$g)==1) $g = '0'$g
if (strlen$b)==1) $b = '0'$b
return $r$g$b
}
Category: View
eXorithm – Execute Algorithm: View / Run Algorithm watermark_image
function watermark_image ($image, $watermark, $position, $margin, $transparency
{
  $w = imagesx$image);
  $h = imagesy$image);
 Â
  $ww = imagesx$watermark);
  $hw = imagesy$watermark);
 Â
  $image2 = image_create_alpha$w, $h);
  imagecopy$image2, $image, 0, 0, 0, 0, $w, $h);
 Â
  imagealphablending$image2, true);
  imagesavealpha$image2, true);
 Â
  switch ($position) {
    case 'tl'
      $top = $margin
      $left = $margin
      break
    case 'tr'
      $top = $margin
      $left = $w$ww$margin
      break
    case 'br'
      $top = $h$hw$margin
      $left = $w$ww$margin
      break
    case 'bl'
      $top = $h$hw$margin
      $left = $margin
      break
    default
      $top = ($h$hw)/2;
      $left = ($w$ww)/2;
  }
 Â
  if ($transparency>0)
    imagecopy$image2, add_transparency$watermark, $transparency), $left, $top, 0, 0, $ww, $hw);Â
  else
    imagecopy$image2, $watermark, $left, $top, 0, 0, $ww, $hw);
 Â
  return $image2
}Â
eXorithm – Execute Algorithm: View / Run Algorithm generate_graph_color
function generate_graph_color ($number
{
$nums = array(2,6,18,8,20,24,5,15,1,22,19,21,11,3,9,4,10,12,14,16,7,17,23,25,13,0,26);
$color = $nums$number % count$nums)];
$color = base_convert$color, 10, 3);
$r = floor$color / 100);
$g = floor(($color % 100) / 10);
$b = ($color % 10);
$r = dechex$r*127);
$g = dechex$g*127);
$b = dechex$b*127);
if (strlen$r)==1) $r = '0'$r
if (strlen$g)==1) $g = '0'$g
if (strlen$b)==1) $b = '0'$b
return $r$g$b
}
eXorithm – Execute Algorithm: View / Run Algorithm namePrefix
function namePrefix ($number
{
//Similar scrip in jquery https://jsfiddle.net/ayn_/z2677vs5/
$currentNum = $number
$currentNum = preg_replace'{/s|,|$|h}', '', $currentNum);
if ($currentNum > 999 && $currentNum < 999999) {
$newNum = ($currentNum / 1000);
$newNum = floor$newNum*100)/100 . 'k'
} else if ($currentNum > 999999) {
$newNum = ($currentNum / 1000000);
$newNum = floor$newNum*100)/100 . 'M'
} else {
$newNum = 'Error, number format is invalid'
}
return $newNum
}
eXorithm – Execute Algorithm: View / Run Algorithm allocate_color
function allocate_color ($image, $color, $transparency
{
if (preg_match'/[0-9ABCDEF]{6}/i', $color)==0) {
throw new Exception"Invalid color code.");
}
if ($transparency<0 || $transparency>127) {
throw new Exception"Invalid transparency.");
}
$r = hexdecsubstr$color, 0, 2));
$g = hexdecsubstr$color, 2, 2));
$b = hexdecsubstr$color, 4, 2));
if ($transparency>127) $transparency = 127;
if ($transparency<=0)
return imagecolorallocate$image, $r, $g, $b);
else
return imagecolorallocatealpha$image, $r, $g, $b, $transparency);
}
eXorithm – Execute Algorithm: View / Run Algorithm invert_color
function invert_color ($color
{
$new = ''
for ($i=0;$i<3;$i++){
$c = 255 - hexdecsubstr$color,(2*$i),2));
$c = dechex$c);
$new .= (strlen$c) < 2) ? '0'$c : $c
}
return $new
}
eXorithm – Execute Algorithm: View / Run Algorithm unity
function unity ($passkey
{
  $ubn = array();
 Â
  while ($passkey > 9) {
    if (strlen$passkey) > 1)
      $passkey = array_sumstr_split$passkey));
    else
      $passkey = $passkey
  }Â
 Â
  $ubn[] = $passkey
 Â
  return end$ubn);
}Â
eXorithm – Execute Algorithm: View / Run Algorithm rounded_rectangle
function rounded_rectangle ($height, $width, $corner_radius, $rectangle_color, $background_color, $background_transparent
{
if (($corner_radius>($height/2)) || ($corner_radius>($width/2))) {
throw new Exception'Corner radius may not exceed half the length of any of the sides.');
}
$image = image_create_alpha$width, $height);
if (!$background_transparent) {
$background_color = allocate_color$image, $background_color);
imagefilledrectangle$image, 0, 0, $width, $height, $background_color);
}
$rectangle_color = allocate_color$image, $rectangle_color);
// draw 2 rectangles that overlap (making an image like the cross on the Swiss flag)
imagefilledrectangle$image, $corner_radius, 0, $width$corner_radius-1, $height, $rectangle_color);
imagefilledrectangle$image, 0, $corner_radius, $width, $height$corner_radius-1, $rectangle_color);
// draw 4 circles for the corners
imagefilledellipse$image, $corner_radius, $corner_radius, $corner_radius*2, $corner_radius*2, $rectangle_color);
imagefilledellipse$image, $width$corner_radius-1, $corner_radius, $corner_radius*2, $corner_radius*2, $rectangle_color);
imagefilledellipse$image, $corner_radius, $height$corner_radius-1, $corner_radius*2, $corner_radius*2, $rectangle_color);
imagefilledellipse$image, $width$corner_radius-1, $height$corner_radius-1, $corner_radius*2, $corner_radius*2, $rectangle_color);
return $image
}
eXorithm – Execute Algorithm: View / Run Algorithm radioactive_decay
function radioactive_decay ($half_life, $time
{
$lambda = log(2)/$half_life
return 100 - 100 * powexp(1), -1 * $lambda * $time);
}
eXorithm – Execute Algorithm: View / Run Algorithm pixelate
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
}