I am working on a project where an admin can create a card template in which they can insert placeholder variables like {first_name}
, {last_name}
, {website}
etc. Then a card will be created by having a user fill in their first name, last name etc. So basically the placeholders will be replaced by the actual content provided by the user. To do that I am creating an SVG image from the template created by the admin and replacing those placeholder variables with the user's data on server side.
The issue is that, if the content provided by the user is too long, then it might extend outside of the canvas boundary, and so might get cut off when the actual card is printed.
Is there some way to detect that, after replacing the placeholders, a canvas element extends outside of the canvas boundary? If so, is there a way to find that element and make it shrink until it fits within the boundary? Basically, I'd like something like this but on server side.
Here's some sample code that I'm using to generate the SVG image:
$message_string = array('{first_name}','{last_name}');
$replace_string = array('Fist Name of User','Last Name Of User');
$front_svg_url = $svg_url.$res_code[0]['front_side_svg_image'];
$front_raw_svg = file_get_contents($front_svg_url);
$front_side_svg = str_ireplace($message_string, $replace_string, $front_raw_svg);
$file_name = uniqid($prefix).".svg";
$file_handle = fopen("$folder_name/".$file_name, 'w');
fwrite($file_handle, $front_side_svg);
fclose($file_handle);
On the server side I am just replacing the variables, so I'm not sure how to achieve this on the server. I am open to any ideas which can achieve my expected output.