Piwik API Symfony 2 - ImageGraph

Hello everybody,

i need to help.
I have already install piwik (http://stats.dev in local (bind/apache)) and my connection between symfony and Piwik is already done.

The problem is, when i’m getting ImageGraph.get with $client->call, my variable return me this


�PNG  IHDR "�E! ^IDATx���a��u����yWtXz� A�B�2M�)C$�2*)� !�� /_HPD���Q/�0���#%G��4z� �� �a׹����>O/��ۛ�������������y��g�{/�����y�Q�u ��Y�b#��@��Xa L`�	,�0���fs����'� ����z��C?n�ȷ�r�4/l�Z���lN>ء���������={���j�F�{��;h �Q����pQ�D&��@��Xa l��a��h�E0ʻ0�Fc��]���������N�%�)��el�%B���0�u�Xe0�ܶ��� 0j�w�ݵa`��� k�zK`���0�����Dp��"v�V]��pL6��ko�&�] �!@��Xa L`�	,��]X�?����l_�v��n�z���nH���8@��Xa L`�	,�0�&��@��Xa L`�	,�0�&��@��Xa L`�	,�0�&��@�ܬa03?x�ϳ�MuJ)��}u�ae��K��z�$�7������;�y���\1�Q�cX"Xa L`�	,�0�&��@��Xa L`�	,�0�&��@��Xa L`�	,�0�&��@��Xa L`�	,�0�&��@��Xa L`� ,�0�&��@��Xa L`�	,�0�&��@��Xa L`�	,�0�&��@��Xa L`�	,�0�&��@��Xa L`�	,�0�&��@��Xa L`�	,�0�&��@��Xa L`���F�q��pјe=�h4꺾�Cل{��dzO��T�R�J�KY�١g��[�y��K�T�T��J���c�e,�[�	��RW}����GOԟ�X���_r׍�'_�h��g�Vn����eu��q��:~��kf=Zv�f�9x�j�f8����5�,X����Y�Lw��3�Ue�?;z��Չ���e��}�^��#O7���=O��q���_��t:��>����P>s��W�!�fsuT =��sf�����ǰ\W����'��8~x�yd�ط:7��b�t��@u���ca����p� �� ��Ҙ%��V���lV�����=a��d�Ы3XS]�z[)��6��n��-����}�,���˾/��t:e~��v����_~���_��7M30���XCK�����Ʀzumbl���z���oVW߷x��_���꺮���{����Ontx0j� ˄k9'���a]��-���ge�^���۫^}�����KW߻R^��u�mu�[��b��^��;_z��r۝�q�� ��,ֲ�=X�o�5X��dٔW{��k����� +gf�.����SVoT�L_-,,�oOy婣[��&-�6�~7����n�ja�Q��;.9�����ʩSe~��ϗn��t��R=x��\���W���Q����bJ��V�� ������{�еo^w�;��u]꺪���-w��.�Օ���/�MصZ���`1�u�`�^�e;q5z|l

So beautiful … :D.

And my Controller is:


<?php
namespace External\PiwikBundle\Controller;

use External\MainBundle\Controller\ExternalController as Controller;
use Knp\PiwikClient\Connection\HttpConnection;
use Knp\PiwikClient\Client;
use Knp\PiwikClient\Connection\PiwikConnection;

class PiwikController extends Controller
{
	public function indexAction()
	{	 
		$connection = new HttpConnection('http://stats.dev');
		$client = new Client($connection, 'myaccesstoken);
		$test = $client->call('ImageGraph.get', array(	'idSite' => 1, 
								'period' => 'day',
								'date' => 'yesterday',
								'apiModule' => 'UserCountry',
								'apiAction' => 'getCountry',
								'outputType' => 0,
								'showLegend' => 1,
								'fontSize' => 9,
								'aliasedGraph' => 1,
								'legendAppendMetric' => 1,
								'format' => 'xml'
								));
		
		 $this->test = $test; // $this->variable => $this->render('thetemplate', array('variable', $variable); ;)
		
	}
}
?>

Twig


{{ test|raw }}

If you have an idea…

Thank you :slight_smile:

Whats the problem with that output?
You are requesting an image and you are getting the binary image data … all fine, or isn’t it? Maybe you should tell what you are trying to do.
There is no different format possible with that. It won’t ever return XML for an image.

Hello Thomas Seifert,

Thank’s for your reply.

I want to get this image, and show this in the webbrowser.

And for the format it’s an error yes.

Well, you are getting the image data. Just output it. Like I said, its the binary image data being returned.

ok, nice you helped me =)

Solution : Add the header (content-type) like


$response->headers->set('Content-Type', 'image/png');

Thank’s Thomas Seifert