Convert CIP

From Phpmaniac

Jump to: navigation, search

Return to Contents

CIP is the image format used by the Cisco 7905/7940/7960 running the sccp/sip firmwares. The raw data is an XML file containing the height, width, and the raw image data itself stored in xml format. CIP data can be retrieved from http://IP_of_phone/CGI/Screenshot

I work for a VOIP company and it is useful for us to able to view screenshots of phones when troubleshooting problems.

The following code pulls the raw image data from a file called "input.txt", processes, resizes, and outputs it in PNG format.

Assumptions:

  1. Input data is from between <data> and </data> tags
  2. Input data is stored in a file called "input.txt"
  3. Input data is trimmed of any whitespace
  4. Input image 160 x 100


  1. <?php
  2.         $string = file_get_contents("input.txt");
  3.         $strlen = strlen($string) + 1;
  4.         $image = imagecreatetruecolor(160, 100);
  5.         $output = imagecreatetruecolor(320, 200);
  6.  
  7.         $data = array();
  8.         $colours = array();
  9.  
  10.         $colours[0] = imagecolorallocate($image, 255, 255, 255);
  11.         $colours[1] = imagecolorallocate($image, 170, 170, 170);
  12.         $colours[2] = imagecolorallocate($image, 85, 85, 85);
  13.         $colours[3] = imagecolorallocate($image, 0, 0, 0);
  14.  
  15.         for($ix = 0; $ix < $strlen; $ix+=2)
  16.         {
  17.                 $data[] = hexdec($string{$ix + 1}) % 4;
  18.                 $data[] = hexdec($string{$ix + 1}) / 4;
  19.                 $data[] = hexdec($string{$ix}) % 4;
  20.                 $data[] = hexdec($string{$ix}) / 4;
  21.         }
  22.  
  23.         $x = 0;
  24.         $y = 0;
  25.         foreach($data as $pixel)
  26.         {
  27.                 imagesetpixel($image, $x, $y, $colours[$pixel]);
  28.                 $x++;
  29.                 if($x == 160)
  30.                 {
  31.                         $y += 1;
  32.                         $x = 0;
  33.                 }
  34.         }
  35.  
  36.         imagecopyresized($output, $image, 0, 0, 0, 0, 320, 200, 160, 100);
  37.  
  38.         header("Content-type: image/png");
  39.         imagepng($output);
  40. ?>

Return to Contents

Personal tools