RRD API response to image

naja7host

Member
May 15, 2009
78
1
6
Helo i'm writing a script based in the API . all well done, the only probleme i have is how to convert the response data of rrd to image (png)


in response i have array

filname -> /var/......./xxx.png
image -> xqsd sdbfsd fs (some trange caractere)

i have tried

HTML:
<img scr="'.$response[image].'.png" alt="cpu chart" *>

but not working .what is the correct format ?
 
Helo i'm writing a script based in the API . all well done, the only probleme i have is how to convert the response data of rrd to image (png)


in response i have array

filname -> /var/......./xxx.png
image -> xqsd sdbfsd fs (some trange caractere)

i have tried

HTML:
<img scr="'.$response[image].'.png" alt="cpu chart" *>

but not working .what is the correct format ?

GET /api2/png/nodes/{node}/qemu/{vmid}/rrd
 
but my code return this

RESPONSE ARRAY:
Code:
Array
(
    [data] => Array
        (
            [filename] => /var/lib/rrdcached/db/pve2-vm/119_cpu.png
            [image] => ‰PNG

IHDR ȟÃ*MbKGDÿÿÿ ½§“ IDATxœÃ*ÂtÕÃÿo+J6ÄÀ²ÙˆAWÃ
A
ÚÊ¡&)¿R„sâ1çôñ9-p|bÂ*Èi򔚢$Â*~mÑ}€s"Â*_ޱµBLÂ%šBҖä‰.ÂÂ¥ld³HvI$$òýc$ø›Â™Â;³{wæý:9s’¹w>ïùÌÎÜÜyûIÇ #â½z,•A@eÃÃPt°TfT¼w èÂ*Â*
YSPP ü@täç瓰®£Ö钒’nŸ5+Þ;0½½½ÇÂ9rdww֬Q¡*;XWz{ëÖ¯O9réž=£n¼1Þ»ðNŸ>Ã*ñxn½õÖÛo¿½¹¹yÒ¤I!Xì`Ú¾ýëÎNBÈ¡7ß|èç?Â֔|‡`0øÃCÃ|óÄÂ9sæ„WHbÃ*«r.üûßo=úè@?!dKwï;qb¼w
à abÂûÇ|ï½÷Z,–Gy¤££ƒÒÙÙ¹páB«ÕºhÑ¢sçÎ    +»~ó¾wE¹zùò§›6Ã…`ä#9È=¬§Ÿ~úµ×^ëèèxæ™g^xáBHYYYvv¶ÛÃ*ÎÊÊ*//V~ôþçùãÇ¿.*zþøñçÂÔé*ºòùç"*~¿_|7Ä+ˆ—BZõà ÂV iõ»¾ ciÉ
ÂÂŽVš2¸^¥åÓÛÛ{ìØ±HĆc4MCRRÿËà    !.—kåʕ)))«VÂ*ª¯¯—ärS“HiˆmñRH«Ò
Ô!Â* ¸vפc,-YÒÑJS׫´LNŸ>ÃØØ˜œœ|ß}÷
;È=¬ßýîw+W®¼Ã*¶Û>ýôÓ.B‚àÙl.**2›Ã]]]ÂÊ·}ûµînÒܜœœ,\Þ|Ç!k„KGo¯H)inž1c†âRóþ§âm%÷M¼”Ù¬)ó¢Éš2/f³¦<ÓhJ%Ây‚f-©®]֔g²V}ߘmKã˜5e^̶¥ò³¨¯¿ÜÃÃ6šJü ֩S§Ž?~Μ9v»=´CÞÿ}›ÃÆq\zzú‰'8ÂŽs»Ãá5W¯^=W_¾rˆööv‘RÉ
â¥ÂV=8¤¨CZApÃ*®/HÇXZ²¤£•¦®iÃ…]š÷©£·¯]»öÙgŸ=ñÄEEE¥¥¥Ë–-KOO/))©¨¨èêêÚ¶m[HýòòòW_}5;ÃrñâEe~üñÇsçÎ1b!äÚµk{֔Â?¾°B,šL¦ÔÔÔÇ|Ñ¢E«W¯&„lذáðáÃv»ýȑ#ëÖÂ*“ç¢Ë%RêñxÄ7¯ ^
iՃCZÂ:¤×îú‚tδ%+@:ZiÊà z•–Éرc;::®^½ÚÑёššR¹y°xà `@k;X/^üüóû»»    !©©©÷ÜsØ1c„é˞™½    0¦4epH+P‡´‚à ºôrÂŒ)-YÒÑJS׫´L’““xà ¹sçÎÂ;÷Â8pà @H8X0(Ьjkkã0“»Z0{`LiÊà ÂV iÃuéåSZ²¤£•¦®Wi™Ô~—ð
ÃŒu°úûû½^o0$×ÃÃ29//dÂpi³ÙDJ‡â++ý*3Sñ¶’û&^Êl֔yÑdM™³YSži4¥”g³YSži”yќiÈZõ}c¶-Âc֔yÑdM™—ZY÷õõµ¶¶*›Ø½à »SCñš‚y°Ø—¦iêÂV\—3BÑHW\,|·ž´FúùÃQF³–¬éhÂ¥)đCZÂ*~KÜæÃŠŒÃ-HòH×´i¿°ÂZc°Âaî¡Ì>Æ6¦4epH+P‡´‚à Ú]_‰+]Øì´‘a!?£YKV€t´Ò”Ãõ*-“@ ÃÔÔ´wïÞ½{÷655ñC›„ÀÃÃ;X‘<*ñRô‡b«¾¾ÞápÂŒ?žrþüù¶¶¶üü|a8X²J!Â*zpH+P‡´‚à ÌÚHñu°DJá`Gš2¸^¥Õ"VmmÃ*ÚµkÜ93iÒ¤—_~yþüùÂÂÂÃ…Ã…Ã…---3f̨ªª²X,!›ÀÃ-€ƒ€ÅV p»ÃüæÉÉÉS¦L7nϡB,¬§žzª²²òìÙ³›6mZ±b!¤¬¬,;;ÛÃ*vgee•——ËŒÃìM€1Â¥)ƒCZÂ:¤gÖF‚ƒ¥zpHG+M\¯Ò27nÜ̙3çÛ7oÞ¼™3g†ô®Hlª3gnܸqÖ¬Y(//ohh°ÛÃ*ûöÃ*ËÈÈðù|ùùùn·;d8X p°Bã`Â8qBè`¥¥¥    +ÄÂÃzýõח,Y2nܸ¥K—nÞ¼™ÃfsQQ‘ÙlîêêV¸Ã*Û¯uwó=Pá²k˖Â5Â¥g×.‘Ò‹.—ÇãQ\Êÿ(ÛVrßÄK™Ãš2/š¬)ób6kÊ3¦Tò˜'h֒êÚeMy¦išõ‹ï‰eýô'ÂŒfMù‰0ۖÆ1kʼ˜mKÃ¥gÃS]}¹¡¡w¸yØ%9zôèäɓgÞ={öl›ÃÖÚÚR!Öý÷ß_QQ‘››ër¹Ö®]ÛÜÜl·Û÷ïßoµZá`@,ƒ€ÂÄ~‹0BÂ’Â’Â’FŽÉûU¹¹¹N§“ã8§Ó™——'3ßߌ„1Ÿ ã὞¤%Õ!Â* 8³¡â(Â1XÂV%¸^Â¥eÂ’ÂÂ}êÔ©ººººººöööìììÂ
±p°ª««ËÊʼ^offæK/½´`ßÃÇ¿E˜““SUUeµZC6ƒZ Çá"”¤ª¼KđĞÉ}Ñ¢E‡‡^°`!$##£¦¦Æï÷×ÔԄ÷®"ÃìM€1Â¥)ƒCZÂ:¤gÖFbÓÃ*I•p°v´ÃÃÃ’Â4ep½Jˤ6ÂŒÂ
˜ÉÃ(+ÂŒÃúC±ƒU[[[PP R3¹Ë*…´êÃ!Â*@Ã’
‚3k#±é`In+îoInÃŽlƒfLiÊà z•V8X` à ` Ä@V¿×ë忕šïc-ù¹+Â×óKžH¥„ÂÆÆFÃ…Â¥m»w+ÞVrßÄK™Ãš2/š¬)ób6kÊ3¦”òLc6kÊ3Â2/Ã*Zš¬~Oa³Â¬~Â÷¬)?fÛÒ8fM™³m©ü¬ûúúZ[[ý~?‰ñÞÂĠBû-Bµ`ö1¶1Â¥)ƒCZÂ:¤×îúJ\iŒÂ´*Ãõ*Â*p°À@ÀÃ@,B¾    0¦4epH+P‡´‚à ÌÚHp°¢ÃV²¤£•¦®Wiµˆ…ƒe2™†~OKK;sæLgg'?“ûŒ3ªªª,KÈ&p°@à ` D™ƒÕÔÔ4iÃ’$«Õš””©N,,î:˗/â‰'!eeeÙÙÙn·;++«¼¼\ffoÂŒ)MÃ’
Ô!Â* 8³6¬h·•¬éhÂ¥)đUZֆsÃùóç÷Ã*ÛwêÔ©¾¾¾aëÄnVOOOVVÖ¿þõ/«Õۗ‘‘áóùòóóÃnwHe8X p°B3«¯¯¯££ãË/¿¼å–[n¿ýö±cÇ
Kc7ëøÃüùóùoƒf³¹¨¨Èl6wuu    «
ÜöÃ*׺»ù¨pÙµeKÈáÒ³k—H)?+†âRþGÙ¶’û&^Êl֔yÑdM™³YSži4¥’ÇÿaNNNUUÿÜP,Ã8XIx«¾¾~¨wEÉÈȨ©©ñûý555ὫH0{`LiÊà ÂV iÙµ‘à `E»Â*dHG+M\¯Òj™ÜÀ@ÀÃ@HÂ;XªÀìM€1Â¥)ƒCZÂ:¤gÖF‚ƒÃ*¶’ Â*4ep½J«,0p°¢–ƒU[[[PP \܃Õßßïõzƒà ¹ÞÇZòsW„¯ç—<‘J    !ŠKÛvïV¼Â*侉—2›5e^4YSæÅl֔gM)噯l֔ge^Úµ*4Y;üžÂfÂ…Y;ü‡?nYS~"̶¥q̚2/fÛRùY÷õõµ¶¶úý~¢p°À@ÀÃ@ˆb«6lzRÖ,˜}ÂŒmLiÊà ÂV iõ»¾Wc° Â*Jp½JË¤à »„W€ƒB4KfoÂŒ)MÃ’
Ô!Â* 8³6¬h·•¬éhÂ¥)đUZá&,0p°¢ØÃ
'Nœà 7ONNž2eJZZš°B,¬þþþ
6dee¥¤¤˜L&BHggç…Â*Vë¢E‹ÎÂ;'3³7Ɣ¦iêÂVœY    V´ÛJV€t´Ò”Ãõ*-“£GÂNž


        )

)

END RESPONSE ARRAY.

now how i can put it or convert it to images ?

i have tried

<img border="0" title="Disk Usage" alt="" src="'.$response['image'].'" />

and

<img border="0" title="Disk Usage" alt="" src="data:image/png;base64,'.$response['image'].'" />

but i can't get it working . i have missed some tips ?
 
Last edited:
No, the API return the png file when called as suggested.

but how i can include it in the IMG tag ;

<img border="0" title="Disk Usage" alt="" src="'.$response['filename'].'" /> ----> not working

<img border="0" title="Disk Usage" alt="" src="'.$response['image'].'.png" /> ----> not working
 
but how i can include it in the IMG tag ;

<img border="0" title="Disk Usage" alt="" src="'.$response['filename'].'" /> ----> not working

<img border="0" title="Disk Usage" alt="" src="'.$response['image'].'.png" /> ----> not working




<img border="0" title="Disk Usage" alt="" src="https://node:8006/api2/png/nodes/{node}/qemu/{vmid}/rrd...." /> -

or

<img border="0" title="Disk Usage" alt="" src="script.php" />

and if your script, you need to return the binary file with correct mime type
 
i'm using the API . i have the api response as shown in my post-4 .

so i have this code but not working .

<img src="data:image/png;base64,'.base64_encode($response['image']).'" />
 
i'm using the API . i have the api response as shown in my post-4 .

so i have this code but not working .

<img src="data:image/png;base64,'.base64_encode($response['image']).'" />

indeed, embedding with base64 should also work.

But I'm not sure your need ' character.

you can try to generate a sample with this website http://webcodertools.com/imagetobase64converter
 
indeed, embedding with base64 should also work.

But I'm not sure your need ' character.

you can try to generate a sample with this website http://webcodertools.com/imagetobase64converter

this is very strange , this is the full code , but not working

PHP:
<?php
require("pve2_api.class.php");
$pve2 = new PVE2_API("xxxxxx.com", "apiuser", "pve", "apipassword");
if ($pve2->constructor_success()) {
    /* Optional - enable debugging. It print()'s any results currently */
    // $pve2->set_debug(true);
    if ($pve2->login()) {
        $node_name = $pve2->get_node_list();
        $first_node = $node_name[0];        
        unset($node_name);        
        $response = $pve2->get("/nodes/".$first_node."/openvz/119/rrd?ds=cpu&timeframe=hour&cf=AVERAGE&_dc=2");
        echo '<img src="data:image/png;base64,'.base64_encode($response['image']).'" />' ;
    } else {
        print("Login to Proxmox Host failed.\n");
        exit;
    }
} else {
    print("Could not create PVE2_API object.\n");
    exit;
}

?>
 
Hi naja7host,

I asked that on the mailing list as I have the same problem and I got the answer.

using the function above, you get an utf8 encoded string.

the treatment in php is with utf8_decode()

best
 
<img src="data:image/png;base64,<? echo base64_encode(utf8_decode($vpsCls->metrics->data->image));?>" />