Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SVG not being generated. #128

Open
rashidaghadiinfotech opened this issue Jul 7, 2021 · 0 comments
Open

SVG not being generated. #128

rashidaghadiinfotech opened this issue Jul 7, 2021 · 0 comments

Comments

@rashidaghadiinfotech
Copy link

rashidaghadiinfotech commented Jul 7, 2021

Hello guys,
I am creating svg based on text and creating it with font ttf file. But it need y axis to be set around 90, 150 etc. Text svg is not being generated properly. Can anyone help me to resolve this?

$f_size = 228;
$size = "16 CM x 39 CM";
$svg_width = 608;	//16*38
$svg_height = 1482; 	 //39*38 CM to px
$font_size = $f_size ."px";
$font_name = "PT Sans";	
$font_path = "fonts/".str_replace(" ","-",$font_name).".ttf";
$texts = "This#Is#User#Test";
$texts = explode("#",$texts);
$font_color = "#fcd90e";
$font_weight = "normal";
$textanchor = "center";	
$y = 90;  // HERE HELP NEEDED

$transform = "";
if($transform == "mirror"){
	$transform = "scale(-1, 1)";
	if($textanchor == "center"){
		$x = -intval($svg_width/2)."px";
		$Tanchor = "middle";
	}elseif($textanchor == "right"){
		$x = -10 ."px";
		$Tanchor = "end";
	}else{
		$x = -intval($svg_width) + 10 ."px";
		$Tanchor = "start";
	}
}else{
	if($textanchor == "center"){
		$x = intval($svg_width/2)."px";
		$Tanchor = "middle";
	}elseif($textanchor == "right"){
		$x = intval($svg_width)."px";
		$Tanchor = "end";
	}else{
		$x = '10px';
		$Tanchor = "start";
	}
}

$svg = new \SVG\SVG($svg_width, $svg_height);
$font = new \SVG\Nodes\Structures\SVGFont($font_name, $font_path);
$svg->getDocument()->addChild($font);
foreach($texts as $text){
	$svg->getDocument()->addChild(
	   (new \SVG\Nodes\Texts\SVGText($text, $x, $y, $transform) )
		 ->setFont($font)
		 ->setSize($font_size)
		 ->setColor($font_color)
		 ->setWeight($font_weight)
		 ->setTextAnchor($Tanchor)
	);
	$y = intval($y) + intval($font_size) + 5;
}
$image = SVG::fromString($svg);

header('Content-Type: image/svg+xml');
echo $image; 

Here is the code I am referring to.
Setting up $y is main problem, Sometimes text can be in 3 lines and sometimes those can be in 4 lines.
Any idea how to make it. ?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant