|
Filed Under (PHP Code Samples) by Anoop on June-14-2007
Code (php) <? function applytext($file,$text,$Position,$fontsize,$font,$newfile,$Margin = 5) { if($newfile == '') $newfile = $file; $fontangle = 0; $Type = strtolower(strrchr($file,'.')); if($Type == '.jpg' || $Type == '.jpeg') $simg = @imagecreatefromjpeg( $file ); if($Type == '.gif') $simg = @imagecreatefromgif( $file ); if($Type == '.png') $simg = @imagecreatefrompng( $file ); if(!$simg) return 0; $currwidth = imagesx($simg); $currheight = imagesy($simg); $im = imagecreatetruecolor($currwidth, $currheight); $Imah = imagecopyresampled($im, $simg, 0, 0, 0, 0, $currwidth, $currheight, $currwidth, $currheight); // Get exact dimensions of text string $box = @imageTTFBbox($fontsize,$fontangle,$font,$text); // Get width and height of text from dimensions $textwidth = abs($box[4] - $box[0]); $textheight = abs($box[5] - $box[1]); $FW = $textwidth; $FH = $textheight; switch($Position) { case "center" : { $xcord = ($currwidth/2)- ($FW/2); $ycord = ($currheight/2)- ($FH/2); break; } case "top-left" : { $xcord = $Margin; $ycord = $FH+$Margin; break; } case "top-right" : { $xcord = ($currwidth- ($FW+$Margin)); $ycord = $FH+$Margin; break; } case "bottom-left" : { $xcord = $Margin; $ycord = $currheight - ($FH+$Margin); break; } case "bottom-right" : { $xcord = ($currwidth- ($FW+$Margin)); $ycord = ($currheight - ($FH+$Margin)); break; } } $color = imagecolorallocate($im, 0, 0, 0); imagettftext ( $im, $fontsize, $fontangle, $xcord+2 , $ycord+1 , $fontcolor, $font, $text ); $color = imagecolorallocate($im, 255, 255, 255); imagettftext ( $im, $fontsize, $fontangle, $xcord, $ycord, $color, $font, $text ); if($Type == '.jpg' || $Type == '.jpeg') { imagejpeg( $im, "$newfile" ); } if($Type == '.gif') { imagegif( $im, "$newfile" ); } if($Type == '.png') { imagepng( $im, "$newfile" ); } imagedestroy($im); return 1; } $iscreated = applytext("clippart.jpg",'www.teckjunk.websewak.com','center','15','arial.ttf','new.jpg'); //applytext('[targetimagefile]','[text to apply]','[position]','[font size]','[font]','[saveas]','[margin]'); ?>
Post a comment
|
|