how to use url2png service in symfony twig files

url2png service for php I am using this function in script tag in twig file of symfony project.

   <script>
 function url2png_v6($url) 
{
   $URL2PNG_APIKEY = "PXXXX";
   $URL2PNG_SECRET = "SXXXX";

    $options['url'] = urlencode($url);
    # usage
    $options['unique'] = round(time() / 60 / 60, 0);     
    $options['fullpage'] = 'false';    
    $options['thumbnail_max_width'] = 'false';      
    $options['viewport'] = "1280x1024"; 
 
    foreach ($options as $key => $value) {
        $_parts[] = "$key=$value";
    }
    $query_string = implode("&", $_parts);
    $TOKEN = md5($query_string . $URL2PNG_SECRET);

    return "https://api.url2png.com/v6/$URL2PNG_APIKEY/$TOKEN/png/?$query_string";
}
   </script>

I am calling this function into html twig body as like

      <div class="vehicle-img mx-auto">                                            
          <img alt="eRideshare" src="{{url2png_v6(company.website_url)}}" >
      </div>

the variable company.website_url returns the exact url example:www.example.com
it returns the error that function is unknown.

enter image description here

How can I use this function in twig body