Search code examples
xmlimagebase64encode

Conversion of image from XML response


I have a problem here identifying which method to use to display images sent from XML. I receive the following XML response :-

   <?xml version="1.0" encoding="UTF-8"?>
   <soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/">
   <soapenv:Header>
         <i18n:international xmlns:i18n="http://www.w3.org/2005/09/ws-i18n">
         <i18n:locale>en_US</i18n:locale></i18n:international>
    </soapenv:Header>
     <soapenv:Body>
     <get:GetCustAreaSnapshotResponseParam  xmlns:get="http://tnb.com.my/CGIS/D/getcustareasnapshotcon">
     <ResponseHdr>
     <ns2:ResponseId xmlns:ns2="http://www.tnb.com.my/CGIS/schemas/bsmfpro" xmlns:ns1="http://tnb.com.my/CGIS/D/getcustareasnapshotpro">02946A91565A40210000013AB9B58E97</ns2:ResponseId>
     <ns2:ResTransactionId xmlns:ns2="http://www.tnb.com.my/CGIS/schemas/bsmfpro" xmlns:ns1="http://tnb.com.my/CGIS/D/getcustareasnapshotpro">111112100334570</ns2:ResTransactionId>
  <ns2:ProviderId xmlns:ns2="http://www.tnb.com.my/CGIS/schemas/bsmfpro" xmlns:ns1="http://tnb.com.my/CGIS/D/getcustareasnapshotpro">CGIS</ns2:ProviderId>
   <ns2:ResTimestamp xmlns:ns2="http://www.tnb.com.my/CGIS/schemas/bsmfpro" xmlns:ns1="http://tnb.com.my/CGIS/D/getcustareasnapshotpro">2012-11-01T10:03:34.000+08:00</ns2:ResTimestamp>
    <ns2:ResStatus xmlns:ns2="http://www.tnb.com.my/CGIS/schemas/bsmfpro" xmlns:ns1="http://tnb.com.my/CGIS/D/getcustareasnapshotpro">SUCC</ns2:ResStatus>
  <ns2:MsgCode xmlns:ns2="http://www.tnb.com.my/CGIS/schemas/bsmfpro" xmlns:ns1="http://tnb.com.my/CGIS/D/getcustareasnapshotpro">IM-001</ns2:MsgCode>
   <ns2:MsgDesc xmlns:ns2="http://www.tnb.com.my/CGIS/schemas/bsmfpro" xmlns:ns1="http://tnb.com.my/CGIS/D/getcustareasnapshotpro">Map Data Successfully Return to external Systems.</ns2:MsgDesc>
   </ResponseHdr>
   <ResGetCustAreaSnapshot>
       <cmc:GetCustAreaSnapshot xmlns:cmc="http://tnb.com.my/CGIS/D/cmc_customermgnt">
              <cmc:MAP_IMAGE_ZOOM1000>iVBORw0KGgoAAAANSUhEUgAAAaQAAAGkCAYAAAB+TFE1AAAQJUlEQVR4nO3d3XbbthZGUbgj7w==</cmc:MAP_IMAGE_ZOOM1000>
              <cmc:MAP_IMAGE_ZOOM2000>iVBORw0KGgoAAAANSUhEUgAAAaQAAAGkCAYAAAB+TFE1AAAHoElEQVR4nO3d3XKaUBhA0UMn7w==</cmc:MAP_IMAGE_ZOOM2000>
              <cmc:MAP_IMAGE_ZOOM4000>iVBORw0KGgoAAAANSUhEUgAAAaQAAAGkCAYAAAB+TFE1AAAHCklEQVR4nO3dya6bMABAUVPl</cmc:MAP_IMAGE_ZOOM4000>
       </cmc:GetCustAreaSnapshot>
  </ResGetCustAreaSnapshot>
  </get:GetCustAreaSnapshotResponseParam>

I am supposed to extract out MAP_IMAGE_ZOOM then use base64_decode. After decoding the string i receive the following when i echo out the result :-

 ‰PNG  IHDR¤¤~LQ5%IDATxœíÝÝvÛ¶FQ¸#ï

What type of encoding this is ?? And how am I suppose to display it as an image ?? I have tried :

 file_put_contents('test4000.png',  base64_decode($bin));

but the image displayed is just blank.

I also tried the following and also received a blank image :

 $img = html_entity_decode(base64_decode($bin), ENT_COMPAT,'ISO-8859-1');
 Header("Content-Type: image/png");
 die($img);

Would greatly appreciate any help given.

Thanks


Solution

  • This is PNG file, with an IHDR chunk and an IDAT chunk. These are described in http://www.libpng.org/pub/png/spec/1.2/PNG-Chunks.html See also the previous page, http://www.libpng.org/pub/png/spec/1.2/PNG-Structure.html for overall PNG structure.

    The IHDR content tells me it's a 420x420 image, 8 bits deep in RGBA triples (color, with transparency).

    IDAT is suspiciously short, but maybe the image is all one color with a tiny squiggle somewhere, or a very simple image. I toyed with your base64 string in Python, and saved the decoded data as a PNG file. Image reading apps tell me "read error" or "cannot load image", so probably your IDAT is bad, or using a compression algorithm unknown to typical image readers.