Create a jpg from svg with PHP, Imagick

I need to export as PDF a file which contains a jpg, that came from a svg, that came from a HighCharts chart. I have this method to :

 public function exportChartToPDFAction(Request $request){
    extract($_REQUEST);

    $chartImage = '/tmp/tempchartimg.png';
    $text = "<p>Estacion: $estacion_nombre</p>";
    $text .= "<p>UbicaciĆ³n (EPSG:32719): $estacion_coordenadas</p>";

    $image = new Imagick();
    $image->readImageBlob( '<?xml version="1.0" encoding="UTF-8" standalone="no"?>' . $chart );
    $image->setImageFormat("jpeg");
    $image->setImageCompressionQuality(90);
    $image->resizeImage(600, 400, imagick::FILTER_LANCZOS, 1);
    $image->writeImage($chartImage);

    // Generating PDF
    $facade = $this->get('ps_pdf.facade');
    $response = new Response();
    $this->render('FrontendBundle:Default:export_climograph_to.pdf.twig', array(
        "title"=>$title,
        "text"=>$text,
        "chart"=>$chartImage
    ), $response);
    $xml = $response->getContent();
    $content = $facade->render($xml);

    return new Response($content, 200, array('content-type' => 'application/pdf'));
}

The error that I get is this:

ERR_EMPTY_RESPONSE

The problem is with line:
$image->readImageBlob( '<?xml version="1.0" encoding="UTF-8" standalone="no"?>' . $chart );

If I comment only that line I have no errors, of course, I’m not getting what I need but the scripts doesn’t die. For example, I check (while the mentioned line is commented) with:

return new JsonResponse( array('$chart'=>$chart ) );

and there I can see a JSON with the value of $chart, BUT, this valu has this form:

{
  "$chart": "u003Csvg xmlns:xlink=u0022http://www.w3.org/1999/xlinku0022 version=u00221.1u0022 class=u0022highcharts-rootu0022 style=u0022font-family:u0026quot;lucida grandeu0026quot;, u0026quot;lucida ETC...........
}

So, it seems that I need to do something with $chartin order to get readImageBlob() working…

Is that correct?
What I need to do then with $chart and keep it clean without those special escapes and characters?
Do I have another error?


Source: stackoverflow-php