Creating Text WordArt Effects

Questions and postings pertaining to the usage of ImageMagick regardless of the interface. This includes the command-line utilities, as well as the C and C++ APIs. Usage questions are like "How do I use ImageMagick to create drop shadows?".
TheBuzzer

Creating Text WordArt Effects

Post by TheBuzzer »

I need some tips in creating text effects such as
the effects on
http://www.customink.com/lab/?E=ideas@c ... 511&I=true

Completed:
Normal Text
Curve Text
Arc Text
Roof Text
Wedge Text

Incomplete:
Bridge Text
Valley Text
Bulge Text

I trying to make a nice class that could generate wordart effects because I dont see any class that could do it simply.

here is my source so far:

Code: Select all

<?php
require('svgcurve.php');

$_GET['shape'] = "test";
$_GET['shapesetting'] = "2";
$_GET['text'] = "arial.ttf";
$_GET['textstring'] = "SUPERMAN";
$_GET['textcolor'] = "green";
$_GET['textsize'] = 50;
$_GET['outline'] = "5";
$_GET['outlinecolor'] = "blue";
$_GET['rotatedegree'] = "0";

$_GET['textstring'] = addslashes($_GET['textstring']);


class WordArt
{
	var $dataArray;
	function WordArt($dataArray)
	{
		$this->dataArray = $dataArray;
	}

	function generatetmp($filetype = "tmp")
	{
		$myFile = tempnam(getcwd(),$filetype);
		rename($myFile, basename($myFile,".tmp").".$filetype");
		return basename($myFile,".tmp").".$filetype";
	}

	function drawSVGCurve()
	{
		$mySVGFile = $this->generatetmp("svg");

		$curveamount = -4;
		$mysvgcurve = new SVGCurve($this->dataArray['textstring'],$this->dataArray['text'], $curveamount, $this->dataArray['textcolor'], $this->dataArray['textsize'], $this->dataArray['outlinecolor'], $this->dataArray['outline']);
		$mysvgcurve->saveSVG($mySVGFile);
		shell_exec('java -jar c:\\batik-1.7\batik-rasterizer.jar '.$mySVGFile);
		unlink($mySVGFile);

		$myFile1 = explode(".",$mySVGFile);
		$myFile2 = $myFile1[0].".png";

		shell_exec('convert "'.$myFile2.'" -background none -trim -rotate '.$this->dataArray['rotatedegree'].' -trim '.$myFile2);


		Header('Content-Type: image/png');
		Header('Content-Length: '.filesize($myFile2));
		readfile($myFile2);
		unlink($myFile2);

	}

	function drawCurve()
	{
		if ($this->dataArray['shapesetting'] == 1) //Up Very Sharp
			$curveamount = 360;
		else if ($this->dataArray['shapesetting'] == 2) //Up Sharp
			$curveamount = 180;
		else if ($this->dataArray['shapesetting'] == 3) //Up Medium
			$curveamount = 90;
		else if ($this->dataArray['shapesetting'] == 4) //Up Slight
			$curveamount = 45;
		else if ($this->dataArray['shapesetting'] == 5) //Up Very Slight
			$curveamount = 22.5;
		else if ($this->dataArray['shapesetting'] == 6) //Up Super Slight
			$curveamount = 11.25;
		else if ($this->dataArray['shapesetting'] == 7) //Down Super Slight
			$curveamount = 11.25;
		else if ($this->dataArray['shapesetting'] == 8) //Down Very Slight
			$curveamount = 22.5;
		else if ($this->dataArray['shapesetting'] == 9) //Down Slight
			$curveamount = 45;
		else if ($this->dataArray['shapesetting'] == 10) //Down Medium
			$curveamount = 90;
		else if ($this->dataArray['shapesetting'] == 11) //Down Sharp
			$curveamount = 180;
		else if ($this->dataArray['shapesetting'] == 12) //Down Very Sharp
			$curveamount = 360;
		else
			$curveamount = 0;

		if ($this->dataArray['shapesetting'] > 6)
		{
			$rotatearound = 180;
			$this->dataArray['rotatedegree'] -= 180;
		}
		else
			$rotatearound = 0;


		$myFile1 = $this->generatetmp("png");
		$myFile2 = $this->generatetmp("png");

		shell_exec('convert -background none -font c:\\windows\\fonts\\'.$this->dataArray['text'].'  -fill '.$this->dataArray['textcolor'].' -pointsize '.$this->dataArray['textsize'].' label:"'.$this->dataArray['textstring'].'" '.$myFile2);
		if ($this->dataArray['outline'] > 0)
		{
			shell_exec('convert -background none -font c:\\windows\\fonts\\'.$this->dataArray['text'].' -fill '.$this->dataArray['textcolor'].' -stroke '.$this->dataArray['outlinecolor'].' -strokewidth '.$this->dataArray['outline'].' -pointsize '.$this->dataArray['textsize'].' label:"'.$this->dataArray['textstring'].'" '.$myFile1);
			shell_exec('composite  -gravity center '.$myFile2.' '.$myFile1.' '.$myFile2);
		}
		shell_exec('convert '.$myFile2.' -background none -trim -bordercolor none -border 1 -distort Arc "'.$curveamount.' 0" -rotate '.$this->dataArray['rotatedegree'].' -trim '.$myFile2);



		Header('Content-Type: image/png');
		Header('Content-Length: '.filesize($myFile2));
		readfile($myFile2);
		unlink($myFile1);
		unlink($myFile2);
	}

	function drawNormal()
	{
		$myFile1 = $this->generatetmp("png");
		$myFile2 = $this->generatetmp("png");

		shell_exec('convert -background none -font c:\\windows\\fonts\\'.$this->dataArray['text'].'  -fill '.$this->dataArray['textcolor'].' -pointsize '.$this->dataArray['textsize'].' label:"'.$this->dataArray['textstring'].'" '.$myFile2);
		if ($this->dataArray['outline'] > 0)
		{
			shell_exec('convert -background none -font c:\\windows\\fonts\\'.$this->dataArray['text'].' -fill '.$this->dataArray['textcolor'].' -stroke '.$this->dataArray['outlinecolor'].' -strokewidth '.$this->dataArray['outline'].' -pointsize '.$this->dataArray['textsize'].' label:"'.$this->dataArray['textstring'].'" '.$myFile1);
			shell_exec('composite  -gravity center '.$myFile2.' '.$myFile1.' '.$myFile2);
		}
		shell_exec('convert '.$myFile2.' -background none -trim -rotate '.$this->dataArray['rotatedegree'].' -trim '.$myFile2);

		Header('Content-Type: image/png');
		Header('Content-Length: '.filesize($myFile2));
		readfile($myFile2);
		unlink($myFile1);
		unlink($myFile2);
	}

	function drawArc()
	{
		if ($this->dataArray['shapesetting'] == 1) //Up Very Small
			$curvesize = 5;
		else if ($this->dataArray['shapesetting'] == 2) //Up Small
			$curvesize = 4;
		else if ($this->dataArray['shapesetting'] == 3) //Up Medium
			$curvesize = 3;
		else if ($this->dataArray['shapesetting'] == 4) //Up Large
			$curvesize = 2;
		else if ($this->dataArray['shapesetting'] == 5) //Up Very Large
			$curvesize = 1;
		else if ($this->dataArray['shapesetting'] == 6) //Down Very Small
			$curvesize = 5;
		else if ($this->dataArray['shapesetting'] == 7) //Down Small
			$curvesize = 4;
		else if ($this->dataArray['shapesetting'] == 8) //Down Medium
			$curvesize = 3;
		else if ($this->dataArray['shapesetting'] == 9) //Down Large
			$curvesize = 2;
		else if ($this->dataArray['shapesetting'] == 10) //Down Very Large
			$curvesize = 1;


		$myFile1 = $this->generatetmp("png");
		$myFile2 = $this->generatetmp("png");

		shell_exec('convert -background none -font c:\\windows\\fonts\\'.$this->dataArray['text'].'  -fill '.$this->dataArray['textcolor'].' -pointsize '.$this->dataArray['textsize'].' label:"'.$this->dataArray['textstring'].'" '.$myFile2);
		if ($this->dataArray['outline'] > 0)
		{
			shell_exec('convert -background none -font c:\\windows\\fonts\\'.$this->dataArray['text'].' -fill '.$this->dataArray['textcolor'].' -stroke '.$this->dataArray['outlinecolor'].' -strokewidth '.$this->dataArray['outline'].' -pointsize '.$this->dataArray['textsize'].' label:"'.$this->dataArray['textstring'].'" '.$myFile1);
			shell_exec('composite  -gravity center '.$myFile2.' '.$myFile1.' '.$myFile2);
		}
		shell_exec('convert '.$myFile2.' -trim '.$myFile2);

		$size = getimagesize($myFile2);
		$width = $size[0] * 2;
		$height = $size[1];


		if ($this->dataArray['shapesetting'] > 5)
			shell_exec('convert "'.$myFile2.'" -background none -wave '.($height/$curvesize).'x'.$width.' -chop 0x'.($height/$curvesize).'  -rotate '.$this->dataArray['rotatedegree'].' -trim '.$myFile2);
		else
			shell_exec('convert "'.$myFile2.'" -background none -wave '.(-$height/$curvesize).'x'.$width.' -rotate 180 -chop 0x'.($height/$curvesize).' -rotate '.(180+$this->dataArray['rotatedegree']).' -trim '.$myFile2);


		Header('Content-Type: image/png');
		Header('Content-Length: '.filesize($myFile2));
		readfile($myFile2);
		unlink($myFile1);
		unlink($myFile2);
	}


	function drawWedge()
	{
		if ($this->dataArray['shapesetting'] == 1) //Up Widen Slow
			$curvesize = 4;
		else if ($this->dataArray['shapesetting'] == 2) //Up Widen Medium
			$curvesize = 3;
		else if ($this->dataArray['shapesetting'] == 3) //Up Winen Fast
			$curvesize = 2;
		else if ($this->dataArray['shapesetting'] == 4) //Up Narrow Slow
			$curvesize = 4;
		else if ($this->dataArray['shapesetting'] == 5) //Up Narrow Medium
			$curvesize = 3;
		else if ($this->dataArray['shapesetting'] == 6) //Up Narrow Fast
			$curvesize = 2;
		else if ($this->dataArray['shapesetting'] == 7) //Middle Widen Slow
			$curvesize = 5;
		else if ($this->dataArray['shapesetting'] == 8) //Middle Widen Medium
			$curvesize = 4;
		else if ($this->dataArray['shapesetting'] == 9) //Middle Widen Fast
			$curvesize = 3;
		else if ($this->dataArray['shapesetting'] == 10) //Middle Widen Slow
			$curvesize = 5;
		else if ($this->dataArray['shapesetting'] == 11) //Middle Widen Medium
			$curvesize = 4;
		else if ($this->dataArray['shapesetting'] == 12) //Middle Widen Fast
			$curvesize = 3;
		else if ($this->dataArray['shapesetting'] == 13) //Down Widen Slow
			$curvesize = 4;
		else if ($this->dataArray['shapesetting'] == 14) //Down Widen Medium
			$curvesize = 3;
		else if ($this->dataArray['shapesetting'] == 15) //Down Winen Fast
			$curvesize = 2;
		else if ($this->dataArray['shapesetting'] == 16) //Down Narrow Slow
			$curvesize = 4;
		else if ($this->dataArray['shapesetting'] == 17) //Down Narrow Medium
			$curvesize = 3;
		else if ($this->dataArray['shapesetting'] == 18) //Down Narrow Fast
			$curvesize = 2;


		$myFile1 = $this->generatetmp("png");
		$myFile2 = $this->generatetmp("png");


		shell_exec('convert -background none -font c:\\windows\\fonts\\'.$this->dataArray['text'].'  -fill '.$this->dataArray['textcolor'].' -pointsize '.$this->dataArray['textsize'].' label:"'.$this->dataArray['textstring'].'" '.$myFile2);
		if ($this->dataArray['outline'] > 0)
		{
			shell_exec('convert -background none -font c:\\windows\\fonts\\'.$this->dataArray['text'].' -fill '.$this->dataArray['textcolor'].' -stroke '.$this->dataArray['outlinecolor'].' -strokewidth '.$this->dataArray['outline'].' -pointsize '.$this->dataArray['textsize'].' label:"'.$this->dataArray['textstring'].'" '.$myFile1);
			shell_exec('composite  -gravity center '.$myFile2.' '.$myFile1.' '.$myFile2);
		}
		shell_exec('convert "'.$myFile2.'" -trim -bordercolor none -border 1 '.$myFile2);

		$size = getimagesize($myFile2);
		$width = $size[0];
		$height = $size[1];

		if ($this->dataArray['shapesetting'] == 1 || $this->dataArray['shapesetting'] == 2 || $this->dataArray['shapesetting'] == 3)
			shell_exec('convert "'.$myFile2.'" -background none -distort Bilinear "0,0,0,'.($height/$curvesize).'  0,'.$height.',0,'.$height.'  '.$width.',0,'.$width.',0  '.$width.','.$height.','.$width.','.$height.'" -trim -rotate '.$this->dataArray['rotatedegree'].' -trim '.$myFile2);
		else if ($this->dataArray['shapesetting'] == 4 || $this->dataArray['shapesetting'] == 5 || $this->dataArray['shapesetting'] == 6)
			shell_exec('convert "'.$myFile2.'" -background none -distort Bilinear "0,0,0,0  0,'.$height.',0,'.$height.'  '.$width.',0,'.$width.','.($height/$curvesize).'  '.$width.','.$height.','.$width.','.$height.'" -trim -rotate '.$this->dataArray['rotatedegree'].' -trim '.$myFile2);
		else if ($this->dataArray['shapesetting'] == 7 || $this->dataArray['shapesetting'] == 8 || $this->dataArray['shapesetting'] == 9)
			shell_exec('convert "'.$myFile2.'" -background none -distort Bilinear "0,0,0,'.($height/$curvesize).'  0,'.$height.',0,'.($height-$height/$curvesize).'  '.$width.',0,'.$width.',0  '.$width.','.$height.','.$width.','.$height.'" -trim -rotate '.$this->dataArray['rotatedegree'].' -trim '.$myFile2);
		else if ($this->dataArray['shapesetting'] == 10 || $this->dataArray['shapesetting'] == 11 || $this->dataArray['shapesetting'] == 12)
			shell_exec('convert "'.$myFile2.'" -background none -distort Bilinear "0,0,0,0  0,'.$height.',0,'.$height.'  '.$width.',0,'.$width.','.($height/$curvesize).'  '.$width.','.$height.','.$width.','.($height-$height/$curvesize).'" -trim -rotate '.$this->dataArray['rotatedegree'].' -trim '.$myFile2);
		else if ($this->dataArray['shapesetting'] == 13 || $this->dataArray['shapesetting'] == 14 || $this->dataArray['shapesetting'] == 15)
			shell_exec('convert "'.$myFile2.'" -background none -distort Bilinear "0,0,0,0  0,'.$height.',0,'.($height-$height/$curvesize).'  '.$width.',0,'.$width.',0  '.$width.','.$height.','.$width.','.$height.'" -trim -rotate '.$this->dataArray['rotatedegree'].' -trim '.$myFile2);
		else if ($this->dataArray['shapesetting'] == 16 || $this->dataArray['shapesetting'] == 17 || $this->dataArray['shapesetting'] == 18)
			shell_exec('convert "'.$myFile2.'" -background none -distort Bilinear "0,0,0,0  0,'.$height.',0,'.$height.'  '.$width.',0,'.$width.',0  '.$width.','.$height.','.$width.','.($height-$height/$curvesize).'" -trim -rotate '.$this->dataArray['rotatedegree'].' -trim '.$myFile2);



		Header('Content-Type: image/png');
		Header('Content-Length: '.filesize($myFile2));
		readfile($myFile2);
		unlink($myFile1);
		unlink($myFile2);
	}


	function drawRoof()
	{
		if ($this->dataArray['shapesetting'] == 1) //Top Small
			$curvesize = 4;
		else if ($this->dataArray['shapesetting'] == 2) //Top Medium
			$curvesize = 3;
		else if ($this->dataArray['shapesetting'] == 3) //Top Large
			$curvesize = 2;
		else if ($this->dataArray['shapesetting'] == 4) //Middle Small
			$curvesize = 5;
		else if ($this->dataArray['shapesetting'] == 5) //Middle Medium
			$curvesize = 4;
		else if ($this->dataArray['shapesetting'] == 6) //Middle Large
			$curvesize = 3;
		else if ($this->dataArray['shapesetting'] == 7) //Bottom Small
			$curvesize = 4;
		else if ($this->dataArray['shapesetting'] == 8) //Bottom Medium
			$curvesize = 3;
		else if ($this->dataArray['shapesetting'] == 9) //Bottom Large
			$curvesize = 2;
		else if ($this->dataArray['shapesetting'] == 10) //Left Small
			$curvesize = 5;
		else if ($this->dataArray['shapesetting'] == 11) //Left Medium
			$curvesize = 4;
		else if ($this->dataArray['shapesetting'] == 12) //Left Large
			$curvesize = 3;
		else if ($this->dataArray['shapesetting'] == 13) //Right Small
			$curvesize = 5;
		else if ($this->dataArray['shapesetting'] == 14) //Right Medium
			$curvesize = 4;
		else if ($this->dataArray['shapesetting'] == 15) //Right Large
			$curvesize = 3;


		$myFile1 = $this->generatetmp("png");
		$myFile2 = $this->generatetmp("png");

		shell_exec('convert -background none -font c:\\windows\\fonts\\'.$this->dataArray['text'].'  -fill '.$this->dataArray['textcolor'].' -pointsize '.$this->dataArray['textsize'].' label:"'.$this->dataArray['textstring'].'" '.$myFile2);
		if ($this->dataArray['outline'] > 0)
		{
			shell_exec('convert -background none -font c:\\windows\\fonts\\'.$this->dataArray['text'].' -fill '.$this->dataArray['textcolor'].' -stroke '.$this->dataArray['outlinecolor'].' -strokewidth '.$this->dataArray['outline'].' -pointsize '.$this->dataArray['textsize'].' label:"'.$this->dataArray['textstring'].'" '.$myFile1);
			shell_exec('composite  -gravity center '.$myFile2.' '.$myFile1.' '.$myFile2);
		}
		shell_exec('convert "'.$myFile2.'" -trim -bordercolor none -border 1 '.$myFile2);

		$size = getimagesize($myFile2);
		$width = $size[0];
		$height = $size[1];

		if ($this->dataArray['shapesetting'] >= 1 && $this->dataArray['shapesetting'] <= 9)
		{
			shell_exec('convert "'.$myFile2.'" -background none -extent '.($width/2).'x'.$height.' '.$myFile1);
			shell_exec('convert "'.$myFile2.'" -background none -extent '.($width/2).'x'.$height.'+'.($width/2).'+0 '.$myFile2);
		}
		else if ($this->dataArray['shapesetting'] >= 10 && $this->dataArray['shapesetting'] <= 12)
		{
			shell_exec('convert "'.$myFile2.'" -background none -extent '.($width/3).'x'.$height.' '.$myFile1);
			shell_exec('convert "'.$myFile2.'" -background none -extent '.($width/3*2).'x'.$height.'+'.($width/3).'+0 '.$myFile2);
		}
		else if ($this->dataArray['shapesetting'] >= 13 && $this->dataArray['shapesetting'] <= 15)
		{
			shell_exec('convert "'.$myFile2.'" -background none -extent '.($width/3*2).'x'.$height.' '.$myFile1);
			shell_exec('convert "'.$myFile2.'" -background none -extent '.($width/3).'x'.$height.'+'.($width/3*2).'+0 '.$myFile2);
		}

		$size1 = getimagesize($myFile1);
		$width1 = $size1[0];
		$height1 = $size1[1];


		$size2 = getimagesize($myFile2);
		$width2 = $size2[0];
		$height2 = $size2[1];


		if ($this->dataArray['shapesetting'] == 1 || $this->dataArray['shapesetting'] == 2 || $this->dataArray['shapesetting'] == 3)
		{
			shell_exec('convert "'.$myFile1.'" -background none -distort Bilinear "0,0,0,'.($height1/$curvesize).'  0,'.$height1.',0,'.$height1.'  '.$width1.',0,'.$width1.',0  '.$width1.','.$height1.','.$width1.','.$height1.'" '.$myFile1);
			shell_exec('convert "'.$myFile2.'" -background none -distort Bilinear "0,0,0,0  0,'.$height2.',0,'.$height2.'  '.$width2.',0,'.$width2.','.($height2/$curvesize).'  '.$width2.','.$height2.','.$width2.','.$height2.'" '.$myFile2);
		}
		else if ($this->dataArray['shapesetting'] == 7 || $this->dataArray['shapesetting'] == 8 || $this->dataArray['shapesetting'] == 9)
		{
			shell_exec('convert "'.$myFile1.'" -background none -distort Bilinear "0,0,0,0  0,'.$height1.',0,'.($height1-$height1/$curvesize).'  '.$width1.',0,'.$width1.',0  '.$width1.','.$height1.','.$width1.','.$height1.'" '.$myFile1);
			shell_exec('convert "'.$myFile2.'" -background none -distort Bilinear "0,0,0,0  0,'.$height2.',0,'.$height2.'  '.$width2.',0,'.$width2.',0  '.$width2.','.$height2.','.$width2.','.($height2-$height2/$curvesize).'" '.$myFile2);
		}
		else
		{
			shell_exec('convert "'.$myFile1.'" -background none -distort Bilinear "0,0,0,'.($height1/$curvesize).'  0,'.$height1.',0,'.($height1-$height1/$curvesize).'  '.$width1.',0,'.$width1.',0  '.$width1.','.$height1.','.$width1.','.$height1.'" '.$myFile1);
			shell_exec('convert "'.$myFile2.'" -background none -distort Bilinear "0,0,0,0  0,'.$height2.',0,'.$height2.'  '.$width2.',0,'.$width2.','.($height2/$curvesize).'  '.$width2.','.$height2.','.$width2.','.($height2-$height2/$curvesize).'" '.$myFile2);
		}


		shell_exec('convert '.$myFile1.' '.$myFile2.' -background none +append -rotate '.$this->dataArray['rotatedegree'].' -trim '.$myFile2);


		Header('Content-Type: image/png');
		Header('Content-Length: '.filesize($myFile2));
		readfile($myFile2);
		unlink($myFile1);
		unlink($myFile2);
	}


	function drawTest()
	{
		// Function Code By fmw42
		$myFile1 = $this->generatetmp("png");
		$myFile2 = $this->generatetmp("png");
		$myFile3 = $this->generatetmp("jpg");

		shell_exec('convert -background none -font c:\\windows\\fonts\\'.$this->dataArray['text'].'  -fill '.$this->dataArray['textcolor'].' -pointsize '.$this->dataArray['textsize'].' label:"'.$this->dataArray['textstring'].'" '.$myFile2);
		if ($this->dataArray['outline'] > 0)
		{
			shell_exec('convert -background none -font c:\\windows\\fonts\\'.$this->dataArray['text'].' -fill '.$this->dataArray['textcolor'].' -stroke '.$this->dataArray['outlinecolor'].' -strokewidth '.$this->dataArray['outline'].' -pointsize '.$this->dataArray['textsize'].' label:"'.$this->dataArray['textstring'].'" '.$myFile1);
			shell_exec('composite  -gravity center '.$myFile2.' '.$myFile1.' '.$myFile2);
		}
		$height=shell_exec('identify -format %h '.$myFile2);
		shell_exec('convert "'.$myFile2.'" -trim -bordercolor none -border '.($height*1).' '.$myFile2);


		//input parameter - amount of distortion (smaller is less, larger is more, 0 is no change)
		$d=-3; //d ranges from 0 to +1 for barrel and 0 to -1 for pincushion

		$a=1+$d;
		$b=-$d;
		$width=shell_exec('identify -format %w '.$myFile2);
		$height=shell_exec('identify -format %h '.$myFile2);
		$w2=$width/2;
		$h2=$height/2;
		$sf=($w2+$h2)/2;
		$xc=$w2;
		$yc=$h2;


		shell_exec('convert -monitor "'.$myFile2.'" -fx "xd=(i-'.$xc.'); yd=(j-'.$yc.'); rd=hypot(xd,yd)/'.$sf.'; ys=(yd/('.$a.'+'.$b.'*rd))+'.$yc.'; u.p{i,ys}" '.$myFile3);


		Header('Content-Type: image/png');
		Header('Content-Length: '.filesize($myFile3));
		readfile($myFile3);
		unlink($myFile1);
		unlink($myFile2);
		unlink($myFile3);

	}



}

$myWordArt = new WordArt($_GET);


if ($_GET['shape'] == "normal")
	$myWordArt->drawNormal();
else if ($_GET['shape'] == "curve")
	$myWordArt->drawCurve();
else if ($_GET['shape'] == "svgcurve")
	$myWordArt->drawSVGCurve();
else if ($_GET['shape'] == "arc")
	$myWordArt->drawArc();
else if ($_GET['shape'] == "wedge")
	$myWordArt->drawWedge();
else if ($_GET['shape'] == "roof")
	$myWordArt->drawRoof();
else if ($_GET['shape'] == "test")
	$myWordArt->drawTest();


?>


<?PHP

class SVGCurve
{
	var $svginformation = "";
	function SVGCurve($textstring,$text,$curveamount, $textcolor, $textsize, $outlinecolor, $outline)
	{
		if (substr_count($text,".") > 0)
		{
			$textarray = explode(".",$text);
			$newstring = "";
			for ($i = 0; $i < count($textarray)-1; $i++)
			{
				$newstring .= $textarray[$i] . ".";
			}
			$newstring=substr($newstring,0,strlen($newstring)-1);
			$text = $newstring;
		}

		$stringinfo = imagettfbbox  ( $textsize , 0  , "c:\\windows\\fonts\\$text.ttf",$textstring);

		//print_r($stringinfo);
		//$stringinfo[7] is height
		//$stringinfo[2] IS length

		$offset = -($stringinfo[7]);
		$offset2 = $stringinfo[2]-$stringinfo[7];


		$this->svginformation .= "<?xml version=\"1.0\" standalone=\"no\"?>";
		$this->svginformation .= "<!DOCTYPE svg PUBLIC \"-//W3C//DTD SVG 1.0//EN\" \"http://www.w3.org/TR/2001/REC-SVG-20010904/DTD/svg10.dtd\">";
		$this->svginformation .= "<svg xmlns=\"http://www.w3.org/2000/svg\" xmlns:xlink=\"http://www.w3.org/1999/xlink\" id=\"body\" width=\"".($offset+$stringinfo[2]+$offset)."\" height=\"".($offset2*2)."\">";

		$this->svginformation .= "<defs>";



			$x1 = $offset;
			$y1 = $offset2;
			$x2 = $offset+$stringinfo[2];
			$y2 = $offset2;
			$x3 = $offset+($stringinfo[2]/2);
			$y3 = $offset2-($stringinfo[2]/2*$curveamount);
			$this->svginformation .= "<path id=\"Curve\" d=\"M $x1 $y1 C $x1 $y1 $x3 $y3 $x2 $y2\" />";


		$this->svginformation .= "</defs>";

		if ($curveamount > 0)
		{
			$this->svginformation .= "<text font-family=\"$text\" font-size=\"$textsize\" fill=\"$textcolor\" stroke=\"$outlinecolor\" stroke-width=\"$outline\" >";
			$this->svginformation .= "<textPath baseline-shift=\"0%\" xlink:href=\"#Curve\" text-anchor=\"middle\" startOffset=\"50%\">$textstring</textPath>";
			$this->svginformation .= "</text>";
			$this->svginformation .= "<text font-family=\"$text\" font-size=\"$textsize\" fill=\"$textcolor\">";
			$this->svginformation .= "<textPath baseline-shift=\"0%\" xlink:href=\"#Curve\" text-anchor=\"middle\" startOffset=\"50%\">$textstring</textPath>";
			$this->svginformation .= "</text>";
		}
		else
		{
			$this->svginformation .= "<text font-family=\"$text\" font-size=\"$textsize\" fill=\"$textcolor\" stroke=\"$outlinecolor\" stroke-width=\"$outline\" >";
			$this->svginformation .= "<textPath baseline-shift=\"-100%\" xlink:href=\"#Curve\" text-anchor=\"middle\" startOffset=\"50%\">$textstring</textPath>";
			$this->svginformation .= "</text>";
			$this->svginformation .= "<text font-family=\"$text\" font-size=\"$textsize\" fill=\"$textcolor\">";
			$this->svginformation .= "<textPath baseline-shift=\"-100%\" xlink:href=\"#Curve\" text-anchor=\"middle\" startOffset=\"50%\">$textstring</textPath>";
			$this->svginformation .= "</text>";
		}

		$this->svginformation .= "</svg>";

	}

	function showSVG()
	{
			header("Content-type: image/svg+xml");
			echo $this->svginformation;
	}

	function saveSVG($myFile)
	{
		$fh = fopen($myFile, 'w') or die("can't open file");
		$stringData = $this->svginformation;
		fwrite($fh, $stringData);
		fclose($fh);
	}

}


//$mysvg = new SVGCurve("THERE ARE NO COW LEVEL","arial", -4, "blue", 50, "yellow", 5);
//$mysvg->showSVG();
//$mysvg->saveSVG("curveimage.svg");

?>
Last edited by TheBuzzer on 2008-04-02T08:17:35-07:00, edited 5 times in total.
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Creating Text WordArt Effects

Post by fmw42 »

User avatar
anthony
Posts: 8883
Joined: 2004-05-31T19:27:03-07:00
Authentication code: 8675308
Location: Brisbane, Australia

Re: Creating Text WordArt Effects

Post by anthony »

Also see. IM Examples, Compound Fonts...
http://imagemagick.org/Usage/fonts/

If you like to contribute methods, please do. I'll try to go over your code when I get back from China.
Anthony Thyssen -- Webmaster for ImageMagick Example Pages
https://imagemagick.org/Usage/
TheBuzzer

Re: Creating Text WordArt Effects

Post by TheBuzzer »

well i figure out 3 shapes now.

normal, curve, and arc


still this is quite hard to figure out with barely and experience with imagemagik.
that example site v6 thing really helps. Been figuring out the different shapes by that site.
TheBuzzer

Re: Creating Text WordArt Effects

Post by TheBuzzer »

well I am getting stuck with the other effects. anyone know what to do to do the other effects?
Bonzo
Posts: 2971
Joined: 2006-05-20T08:08:19-07:00
Location: Cambridge, England

Re: Creating Text WordArt Effects

Post by Bonzo »

Well your wedge effect could be done with distort using perspective; check Anthonys example section for more details:

Code: Select all

<?php

//Create the image with text
$Name='Anthony'; 
$filename = 'anthony.jpg';       
exec("convert -size 125x40 -pointsize 20 -gravity Center  label:$Name $filename"); 

// Carry out the distortion
exec("convert $filename -matte -background none -virtual-pixel background +distort Perspective '0,0 0,40, 125,40, 125,0 0,0 0,40, 125,30, 125,20' -trim output.png");
 
?> 
TheBuzzer

Re: Creating Text WordArt Effects

Post by TheBuzzer »

well i got wedge working.

Had lot of problems with this effect persective showed it weird but billianer looked correct. I had to trim the edges to make it look like it was flat. If there was more white space it somehow bends all sides still so getting rid of edges reduce that effect.
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Creating Text WordArt Effects

Post by fmw42 »

see my script pinbarrel for pincushion and barrel distortions

http://www.fmwconcepts.com/imagemagick/index.html

unfortunately they are rather slow due to the use of -fx.
Bonzo
Posts: 2971
Joined: 2006-05-20T08:08:19-07:00
Location: Cambridge, England

Re: Creating Text WordArt Effects

Post by Bonzo »

I do not know if you know how to run Bash ? scripts with php but this is how I ran one of Freds scripts.

Code: Select all

Download the script and upload it to your server ( I called the script autotrim.sh )
Change the permissions to 755 on the script 
Write your php code like this using the full path to the script
<?php
    // Run the script
    exec("/FULL PATH TO AUTOTRIM/autotrim.sh zelda3_border2w.png fred.png 2>&1", $array); 
    //Display any errors
    echo "<br>".print_r($array)."<br>"; 
    echo "</pre>";
    ?> 
TheBuzzer

Re: Creating Text WordArt Effects

Post by TheBuzzer »

well i finished roof too now. now is those part curved ones i need to figure out ...

going to check fred's site to see if he have anything i could use to make the remaining ones
TheBuzzer

Re: Creating Text WordArt Effects

Post by TheBuzzer »

well i am coding this on windows machine. I would need cgywin to run those scripts it seems like.

maybe someone know some convert command to do the last 4 effect would be helpful.
TheBuzzer

Re: Creating Text WordArt Effects

Post by TheBuzzer »

it seems like i need to use the -fx command but I cant figure out how to use it.
TheBuzzer

Re: Creating Text WordArt Effects

Post by TheBuzzer »

the fx command seems slow too so there should be faster ways to do the other effect without loosing much time isnt there?
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Creating Text WordArt Effects

Post by fmw42 »

When Anthony gets back from his trip in early April, he plans to implement something like my pincushion script directly in IM. So that would speed it up tremendously. Unfortunately, -fx is very slow for this complex a function. The bubblewarp script may work also for you, but is slow also. Some of these effects can be simulated or implemented with distortion maps (look up tables) that can use -fx on a single row for the radius and then apply that using -clut to the image. That will also speed it up a lot, but that gets even more complicated.

See the hourglass and trapezoid distortion map examples at

http://www.imagemagick.org/Usage/distor ... _hourglass

That may give you some clues or ideas.

You can certainly take my scripts and rewrite it for your own applications on Windows or PHP.
TheBuzzer

Re: Creating Text WordArt Effects

Post by TheBuzzer »

k so he will add more effects to speed up the process that would be great.

also i realized the curve text on custom ink is done a unique way.

they dont curve the letters but the letters lie on a curve. wonder how they did that.
Post Reply