Convert CIP
From Phpmaniac
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:
- Input data is from between <data> and </data> tags
- Input data is stored in a file called "input.txt"
- Input data is trimmed of any whitespace
- Input image 160 x 100
- <?php
- $string = file_get_contents("input.txt");
- $strlen = strlen($string) + 1;
- $image = imagecreatetruecolor(160, 100);
- $output = imagecreatetruecolor(320, 200);
- $data = array();
- $colours = array();
- $colours[0] = imagecolorallocate($image, 255, 255, 255);
- $colours[1] = imagecolorallocate($image, 170, 170, 170);
- $colours[2] = imagecolorallocate($image, 85, 85, 85);
- $colours[3] = imagecolorallocate($image, 0, 0, 0);
- for($ix = 0; $ix < $strlen; $ix+=2)
- {
- $data[] = hexdec($string{$ix + 1}) % 4;
- $data[] = hexdec($string{$ix + 1}) / 4;
- $data[] = hexdec($string{$ix}) % 4;
- $data[] = hexdec($string{$ix}) / 4;
- }
- $x = 0;
- $y = 0;
- foreach($data as $pixel)
- {
- imagesetpixel($image, $x, $y, $colours[$pixel]);
- $x++;
- if($x == 160)
- {
- $y += 1;
- $x = 0;
- }
- }
- imagecopyresized($output, $image, 0, 0, 0, 0, 320, 200, 160, 100);
- header("Content-type: image/png");
- imagepng($output);
- ?>
|
|

