Archive for November, 2006

Vertical label creation

Problem You want to generate a vertical image, with text over the top. Solution Here is some code I wrote, which is used extensively on my sites:<?phpheader(“Content-type: image/png”);$string = $_GET['label'];$symbols=array(‘r’,'g’,'b’);for($i=0;$i<count($symbols);$i++) {    $mythis=$symbols[$i]; if(is_numeric($_GET[$mythis])) { $$mythis=$_GET[$mythis]; } else { $$mythis=0; }}$symbols=array(‘tr’,'tg’,'tb’);for($i=0;$i<count($symbols);$i++) {    $mythis=$symbols[$i]; if(is_numeric($_GET[$mythis])) { $$mythis=$_GET[$mythis]; } else { $$mythis=”255″; }}if(isset($_GET['font'])) { $font = $_GET['font']; } else { $font=”2″; }$len=strlen($string);$text_width = imagefontwidth($font);$text_height = imagefontwidth($font);$im  = imagecreate (20, ($len*$text_height)+10); /* Create a blank image */$bgc = imagecolorallocate ($im, $r, $g, $b);$tc  = imagecolorallocate ($im, $tr, $tg, $tb);imagefilledrectangle ($im, 0, 0, 150, 30, $bgc);imagestringup($im, $font, 4, ($len*$text_height)+3, $string, $tc);imagepng($im);imagedestroy($im);?> Example Reference Give it a blast on this site, like this: http://coding-school.com/common/label-up.php?label=your+text+hereAutomatically calculates size required. You can also add font=# – where # is 1 to 5, like [...]

libcurl lookup taking long time

Problem You notice for some hosts curl and/or libcurl are taking 7 or so secs to lookup the host. But nslookup or dig respond almost immediately. Solution Try doing curl -4 -w “time_namelookup: %{time_namelookup}\n” …. and try without the -4. If you see drastic differences, you could be falling foul of the IPV6 bug. To [...]