<?php /** * overlay_image * * Overlay a transparent image on top of another image. * * @version 0.2 * @author Contributors at eXorithm * @link /algorithm/view/overlay_image Listing at eXorithm * @link /algorithm/history/overlay_image History at eXorithm * @license /home/show/license * * @param resource $base (GD image) * @param resource $image (GD image) * @return mixed */ function overlay_image($base=null,$image=null) { $h = imagesy($image); $w = imagesx($image); imagealphablending($base, true); imagesavealpha($base, true); imagecopy($base, $image, 0, 0, 0, 0, $w, $h); return $base; } ?>
Tag: Graph
eXorithm – Execute Algorithm: History For Algorithm check_domain
check_domain    version 0.1    Check a domain name against a whitelist and blacklist.
PI Digits
<?php /** * pi_digits * * Calculate the digits of pi. * * @version 0.4 * @author Contributors at eXorithm * @link /algorithm/view/pi_digits Listing at eXorithm * @link /algorithm/history/pi_digits History at eXorithm * @license /home/show/license * * @param number $digits * @return mixed */ function pi_digits($digits=500) { $n = floor($digits * 14/4); $scale = 10000; $init = 2000; $carry = 0; $result = ''; for($i=0;$i<=$n;$i++) { $arr[$i] = $init; } for($i=$n;$i>0;$i=$i-14) { $sum = 0; for($j=$i;$j>0;$j--) { $sum = ($sum * $j) + ($scale * $arr[$j]); $arr[$j] = $sum % (($j*2)-1); $sum = floor($sum / (($j*2)-1)); } $result .= sprintf("%04d", ($carry + ($sum / $scale))); $carry = $sum % $scale; } if ($digits>1) { return $result[0].'.'.substr($result,1,$digits-1); } else { return substr($result,0,$digits); } } ?>
eXorithm – Execute Algorithm: History For Algorithm round_corners
round_corners    version 0.2    Round the corners of an image. Transparency and anti-aliasing are supported.
Photobucket
<?php /** * photobucket * * Gets all the pictures from a Photobucket album. * * @version 0.2 * @author Contributors at eXorithm * @link /algorithm/view/photobucket Listing at eXorithm * @link /algorithm/history/photobucket History at eXorithm * @license /home/show/license * * @param mixed $url Photobucket URL * @return mixed */ function photobucket($url='http://s283.photobucket.com/albums/kk285/konnarak_1608/romantic/') { $str = file_get_contents($url); preg_match_all('/<img[^>]+>/i',$str, $result); $strPics = ""; foreach( $result as $img_tag) { foreach( $img_tag as $img) { if( !strpos($img, 'class="under off"') ) continue; preg_match('/< *img[^>]*src *= *["\']?([^"\']*)/i', $img, $imgURLs); $imgURL = str_replace("/th_", "/", $imgURLs[1]); $strPics .= $imgURL . "\n"; } } return $strPics; } ?>
Sort Multi Array
<?php /** * sort_multi_array * * Sort a two-dimensional array by one (or more) of the elements in the nested arrays. Accepts a variable number of arguments. * * @version 0.1 * @author Contributors at eXorithm * @link /algorithm/view/sort_multi_array Listing at eXorithm * @link /algorithm/history/sort_multi_array History at eXorithm * @license /home/show/license * * @param array $array Two dimensional array. Each array in the array should have the same keys. * @param mixed $key Key in the sub-arrays to sort by. * @return array */ function sort_multi_array($array=array(0=>array('surname'=>'Smith','givenname'=>'Henrietta'),1=>array('surname'=>'Smythe','givenname'=>'Stuart'),2=>array('surname'=>'Black','givenname'=>'Conrad'),3=>array('surname'=>'Smith','givenname'=>'Abigail'),4=>array('surname'=>'Eaves','givenname'=>'Ruth'),5=>array('surname'=>'Travis','givenname'=>'Earl')),$key='surname') { $keys = array(); for ($i=1;$i<func_num_args();$i++) { $keys[$i-1] = func_get_arg($i); } // create a custom search function to pass to usort $func = function ($a, $b) use ($keys) { for ($i=0;$i<count($keys);$i++) { if ($a[$keys[$i]] != $b[$keys[$i]]) { return ($a[$keys[$i]] < $b[$keys[$i]]) ? -1 : 1; } } return 0; }; usort($array, $func); return $array; } ?>
Hailstone
<?php /** * hailstone * * Calculates a hailstone sequence. http://en.wikipedia.org/wiki/Collatz_conjecture * * @version 0.3 * @author Contributors at eXorithm * @link /algorithm/view/hailstone Listing at eXorithm * @link /algorithm/history/hailstone History at eXorithm * @license /home/show/license * * @param number $number number to start with * @return array */ function hailstone($number=17) { $result = array(); while ($number > 1) { $result[] = $number; if ($number & 1) $number = 3 * $number + 1; else $number = $number / 2; } $result[] = $number; return $result; } ?>
Check Domain
<?php /** * check_domain * * Check a domain name against a whitelist and blacklist. * * @version 0.1 * @author Contributors at eXorithm * @link /algorithm/view/check_domain Listing at eXorithm * @link /algorithm/history/check_domain History at eXorithm * @license /home/show/license * * @param mixed $url * @param array $white_list * @param array $black_list * @return bool */ function check_domain($url='',$white_list=array(0=>'*.gov',1=>'*.gov.ru'),$black_list=array(0=>'*.nk',1=>'*.ru')) { foreach ($white_list as $re) { $re = preg_quote($re); $re = str_replace('\*', '.*', $re); if (preg_match('|^'.$re.'$|', $url)) { return true; } } foreach ($black_list as $re) { $re = preg_quote($re); $re = str_replace('\*', '.*', $re); if (preg_match('|^'.$re.'$|', $url)) { return false; } } return true; } ?>
eXorithm – Execute Algorithm: History For Algorithm unity
unity    version 1.2    Returns digit summation of any numerical value given for passkey (up to 14 digits in length)
Sum List
<?php /** * sum_list * * Sum up the numbers in an array. * * @version 0.1 * @author Contributors at eXorithm * @link /algorithm/view/sum_list Listing at eXorithm * @link /algorithm/history/sum_list History at eXorithm * @license /home/show/license * * @param array $numbers * @return number */ function sum_list($numbers=array(0=>'2',1=>'4',2=>'12',3=>'1')) { return array_sum($numbers); } ?>