ILIAS  release_5-2 Revision v5.2.25-18-g3f80b828510
GetId3\Module\Graphic\Gif Class Reference

GetId3() by James Heinrich info@.nosp@m.geti.nosp@m.d3.or.nosp@m.g //. More...

+ Inheritance diagram for GetId3\Module\Graphic\Gif:
+ Collaboration diagram for GetId3\Module\Graphic\Gif:

Public Member Functions

 analyze ()
 
 GetLSBits ($bits)
 string $bitbuffer More...
 
- Public Member Functions inherited from GetId3\Handler\BaseHandler
 __construct (GetId3Core $getid3, $call_module=null)
 
 analyze ()
 Analyze from file pointer. More...
 
 AnalyzeString (&$string)
 Analyze from string instead. More...
 
 saveAttachment (&$ThisFileInfoIndex, $filename, $offset, $length)
 

Additional Inherited Members

- Protected Member Functions inherited from GetId3\Handler\BaseHandler
 ftell ()
 
 fread ($bytes)
 
 fseek ($bytes, $whence=SEEK_SET)
 
 feof ()
 
 isDependencyFor ($module)
 
 error ($text)
 
 warning ($text)
 
- Protected Attributes inherited from GetId3\Handler\BaseHandler
 $getid3
 
 $data_string_flag = false
 
 $data_string = ''
 
 $data_string_position = 0
 
 $data_string_length = 0
 

Detailed Description

GetId3() by James Heinrich info@.nosp@m.geti.nosp@m.d3.or.nosp@m.g //.

module for analyzing GIF Image files

Author
James Heinrich info@.nosp@m.geti.nosp@m.d3.or.nosp@m.g http://www.getid3.org

Definition at line 29 of file Gif.php.

Member Function Documentation

◆ analyze()

GetId3\Module\Graphic\Gif::analyze ( )
Returns
boolean

Definition at line 36 of file Gif.php.

References $info, GetId3\Handler\BaseHandler\fread(), GetId3\Handler\BaseHandler\fseek(), GetId3\Lib\Helper\LittleEndian2Int(), and GetId3\Lib\Helper\PrintHexBytes().

37  {
38  $info = &$this->getid3->info;
39 
40  $info['fileformat'] = 'gif';
41  $info['video']['dataformat'] = 'gif';
42  $info['video']['lossless'] = true;
43  $info['video']['pixel_aspect_ratio'] = (float) 1;
44 
45  fseek($this->getid3->fp, $info['avdataoffset'], SEEK_SET);
46  $GIFheader = fread($this->getid3->fp, 13);
47  $offset = 0;
48 
49  $info['gif']['header']['raw']['identifier'] = substr($GIFheader, $offset, 3);
50  $offset += 3;
51 
52  $magic = 'GIF';
53  if ($info['gif']['header']['raw']['identifier'] != $magic) {
54  $info['error'][] = 'Expecting "'.Helper::PrintHexBytes($magic).'" at offset '.$info['avdataoffset'].', found "'.Helper::PrintHexBytes($info['gif']['header']['raw']['identifier']).'"';
55  unset($info['fileformat']);
56  unset($info['gif']);
57 
58  return false;
59  }
60 
61  $info['gif']['header']['raw']['version'] = substr($GIFheader, $offset, 3);
62  $offset += 3;
63  $info['gif']['header']['raw']['width'] = Helper::LittleEndian2Int(substr($GIFheader, $offset, 2));
64  $offset += 2;
65  $info['gif']['header']['raw']['height'] = Helper::LittleEndian2Int(substr($GIFheader, $offset, 2));
66  $offset += 2;
67  $info['gif']['header']['raw']['flags'] = Helper::LittleEndian2Int(substr($GIFheader, $offset, 1));
68  $offset += 1;
69  $info['gif']['header']['raw']['bg_color_index'] = Helper::LittleEndian2Int(substr($GIFheader, $offset, 1));
70  $offset += 1;
71  $info['gif']['header']['raw']['aspect_ratio'] = Helper::LittleEndian2Int(substr($GIFheader, $offset, 1));
72  $offset += 1;
73 
74  $info['video']['resolution_x'] = $info['gif']['header']['raw']['width'];
75  $info['video']['resolution_y'] = $info['gif']['header']['raw']['height'];
76  $info['gif']['version'] = $info['gif']['header']['raw']['version'];
77  $info['gif']['header']['flags']['global_color_table'] = (bool) ($info['gif']['header']['raw']['flags'] & 0x80);
78  if ($info['gif']['header']['raw']['flags'] & 0x80) {
79  // Number of bits per primary color available to the original image, minus 1
80  $info['gif']['header']['bits_per_pixel'] = 3 * ((($info['gif']['header']['raw']['flags'] & 0x70) >> 4) + 1);
81  } else {
82  $info['gif']['header']['bits_per_pixel'] = 0;
83  }
84  $info['gif']['header']['flags']['global_color_sorted'] = (bool) ($info['gif']['header']['raw']['flags'] & 0x40);
85  if ($info['gif']['header']['flags']['global_color_table']) {
86  // the number of bytes contained in the Global Color Table. To determine that
87  // actual size of the color table, raise 2 to [the value of the field + 1]
88  $info['gif']['header']['global_color_size'] = pow(2, ($info['gif']['header']['raw']['flags'] & 0x07) + 1);
89  $info['video']['bits_per_sample'] = ($info['gif']['header']['raw']['flags'] & 0x07) + 1;
90  } else {
91  $info['gif']['header']['global_color_size'] = 0;
92  }
93  if ($info['gif']['header']['raw']['aspect_ratio'] != 0) {
94  // Aspect Ratio = (Pixel Aspect Ratio + 15) / 64
95  $info['gif']['header']['aspect_ratio'] = ($info['gif']['header']['raw']['aspect_ratio'] + 15) / 64;
96  }
97 
98 // if ($info['gif']['header']['flags']['global_color_table']) {
99 // $GIFcolorTable = fread($this->getid3->fp, 3 * $info['gif']['header']['global_color_size']);
100 // $offset = 0;
101 // for ($i = 0; $i < $info['gif']['header']['global_color_size']; $i++) {
102 // $red = GetId3_lib::LittleEndian2Int(substr($GIFcolorTable, $offset++, 1));
103 // $green = GetId3_lib::LittleEndian2Int(substr($GIFcolorTable, $offset++, 1));
104 // $blue = GetId3_lib::LittleEndian2Int(substr($GIFcolorTable, $offset++, 1));
105 // $info['gif']['global_color_table'][$i] = (($red << 16) | ($green << 8) | ($blue));
106 // }
107 // }
108 //
109 // // Image Descriptor
110 // while (!feof($this->getid3->fp)) {
111 // $NextBlockTest = fread($this->getid3->fp, 1);
112 // switch ($NextBlockTest) {
113 //
114 // case ',': // ',' - Image separator character
115 //
116 // $ImageDescriptorData = $NextBlockTest.fread($this->getid3->fp, 9);
117 // $ImageDescriptor = array();
118 // $ImageDescriptor['image_left'] = GetId3_lib::LittleEndian2Int(substr($ImageDescriptorData, 1, 2));
119 // $ImageDescriptor['image_top'] = GetId3_lib::LittleEndian2Int(substr($ImageDescriptorData, 3, 2));
120 // $ImageDescriptor['image_width'] = GetId3_lib::LittleEndian2Int(substr($ImageDescriptorData, 5, 2));
121 // $ImageDescriptor['image_height'] = GetId3_lib::LittleEndian2Int(substr($ImageDescriptorData, 7, 2));
122 // $ImageDescriptor['flags_raw'] = GetId3_lib::LittleEndian2Int(substr($ImageDescriptorData, 9, 1));
123 // $ImageDescriptor['flags']['use_local_color_map'] = (bool) ($ImageDescriptor['flags_raw'] & 0x80);
124 // $ImageDescriptor['flags']['image_interlaced'] = (bool) ($ImageDescriptor['flags_raw'] & 0x40);
125 // $info['gif']['image_descriptor'][] = $ImageDescriptor;
126 //
127 // if ($ImageDescriptor['flags']['use_local_color_map']) {
128 //
129 // $info['warning'][] = 'This version of GetId3Core() cannot parse local color maps for GIFs';
130 // return true;
131 //
132 // }
133 //echo 'Start of raster data: '.ftell($this->getid3->fp).'<BR>';
134 // $RasterData = array();
135 // $RasterData['code_size'] = GetId3_lib::LittleEndian2Int(fread($this->getid3->fp, 1));
136 // $RasterData['block_byte_count'] = GetId3_lib::LittleEndian2Int(fread($this->getid3->fp, 1));
137 // $info['gif']['raster_data'][count($info['gif']['image_descriptor']) - 1] = $RasterData;
138 //
139 // $CurrentCodeSize = $RasterData['code_size'] + 1;
140 // for ($i = 0; $i < pow(2, $RasterData['code_size']); $i++) {
141 // $DefaultDataLookupTable[$i] = chr($i);
142 // }
143 // $DefaultDataLookupTable[pow(2, $RasterData['code_size']) + 0] = ''; // Clear Code
144 // $DefaultDataLookupTable[pow(2, $RasterData['code_size']) + 1] = ''; // End Of Image Code
145 //
146 //
147 // $NextValue = $this->GetLSBits($CurrentCodeSize);
148 // echo 'Clear Code: '.$NextValue.'<BR>';
149 //
150 // $NextValue = $this->GetLSBits($CurrentCodeSize);
151 // echo 'First Color: '.$NextValue.'<BR>';
152 //
153 // $Prefix = $NextValue;
154 //$i = 0;
155 // while ($i++ < 20) {
156 // $NextValue = $this->GetLSBits($CurrentCodeSize);
157 // echo $NextValue.'<BR>';
158 // }
159 //return true;
160 // break;
161 //
162 // case '!':
163 // // GIF Extension Block
164 // $ExtensionBlockData = $NextBlockTest.fread($this->getid3->fp, 2);
165 // $ExtensionBlock = array();
166 // $ExtensionBlock['function_code'] = GetId3_lib::LittleEndian2Int(substr($ExtensionBlockData, 1, 1));
167 // $ExtensionBlock['byte_length'] = GetId3_lib::LittleEndian2Int(substr($ExtensionBlockData, 2, 1));
168 // $ExtensionBlock['data'] = fread($this->getid3->fp, $ExtensionBlock['byte_length']);
169 // $info['gif']['extension_blocks'][] = $ExtensionBlock;
170 // break;
171 //
172 // case ';':
173 // $info['gif']['terminator_offset'] = ftell($this->getid3->fp) - 1;
174 // // GIF Terminator
175 // break;
176 //
177 // default:
178 // break;
179 //
180 //
181 // }
182 // }
183  return true;
184  }
static PrintHexBytes($string, $hex=true, $spaces=true, $htmlencoding='UTF-8')
Definition: Helper.php:36
fseek($bytes, $whence=SEEK_SET)
$info
Definition: example_052.php:80
static LittleEndian2Int($byteword, $signed=false)
Definition: Helper.php:413
+ Here is the call graph for this function:

◆ GetLSBits()

GetId3\Module\Graphic\Gif::GetLSBits (   $bits)

string $bitbuffer

Parameters
type$bits
Returns
type

Definition at line 192 of file Gif.php.

References GetId3\Handler\BaseHandler\fread().

193  {
194  static $bitbuffer = '';
195  while (strlen($bitbuffer) < $bits) {
196  $bitbuffer = str_pad(decbin(ord(fread($this->getid3->fp, 1))), 8, '0', STR_PAD_LEFT).$bitbuffer;
197  }
198  $value = bindec(substr($bitbuffer, 0 - $bits));
199  $bitbuffer = substr($bitbuffer, 0, 0 - $bits);
200 
201  return $value;
202  }
+ Here is the call graph for this function:

The documentation for this class was generated from the following file: