-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathPIM.php
More file actions
279 lines (220 loc) · 11 KB
/
PIM.php
File metadata and controls
279 lines (220 loc) · 11 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
<?php
/******************************************************************************
*
* Filename: PIM.php
*
* Description: Provides functions for reading, writing and interpreting a
* Print Image Matching information data block.
*
* Author: Evan Hunter
*
* Date: 23/7/2004
*
* Project: PHP JPEG Metadata Toolkit
*
* Revision: 1.00
*
* URL: http://electronics.ozhiker.com
*
* Copyright: Copyright Evan Hunter 2004
*
* License: This file is part of the PHP JPEG Metadata Toolkit.
*
* The PHP JPEG Metadata Toolkit is free software; you can
* redistribute it and/or modify it under the terms of the
* GNU General Public License as published by the Free Software
* Foundation; either version 2 of the License, or (at your
* option) any later version.
*
* The PHP JPEG Metadata Toolkit is distributed in the hope
* that it will be useful, but WITHOUT ANY WARRANTY; without
* even the implied warranty of MERCHANTABILITY or FITNESS
* FOR A PARTICULAR PURPOSE. See the GNU General Public License
* for more details.
*
* You should have received a copy of the GNU General Public
* License along with the PHP JPEG Metadata Toolkit; if not,
* write to the Free Software Foundation, Inc., 59 Temple
* Place, Suite 330, Boston, MA 02111-1307 USA
*
* If you require a different license for commercial or other
* purposes, please contact the author: evan@ozhiker.com
*
******************************************************************************/
include_once "EXIF.php";
// TODO Find out definitions of Print Image Matching Info tags
/******************************************************************************
*
* Function: Decode_PIM
*
* Description: Decodes the contents of a EXIF tag containing Print Image
* Matching information, and returns the contents as an array
*
* Parameters: tag - An EXIF tag containing Print Image Matching information
* as from get_EXIF_JPEG
* Tag_Definitions_Name - The name of the Tag Definitions group
* within the global array IFD_Tag_Definitions
*
* Returns: newtag - The EXIF tag, modified with the data field containing
* an array of the PIM contents
*
******************************************************************************/
function Decode_PIM( $tag, $Tag_Definitions_Name )
{
// Create a new EXIF tag for the output
$newtag = $tag;
// Check that this tag is for Print Image Matching Info
if ( $tag['Type'] == "PIM" )
{
// Check that the data starts with PrintIM
if ( substr( $tag['Data'], 0, 8 ) == "PrintIM\x00" )
{
// Find the end of the version string
if ( ( $ver_pos = strpos ( $tag['Data'], "\0", 8 ) ) == -1 )
{
// couldn't find the start of the version string
return $newtag;
}
// Create an array to receive the Data
$newtag['Data'] = array( );
// Extract the PrintIM version
$newtag['Data']['Version'] = substr( $tag['Data'], 8, $ver_pos - 8 );
// Skip the position over the version
$count_pos = $ver_pos+2;
// Extract the count of tags - 2 bytes
$PI_tag_count = get_IFD_Data_Type( substr($tag['Data'], $count_pos, 2) , 3, $tag['Byte Align'] );
// Panasonic have put an extra Null after the Version, which
// causes the tag count to be wrong -
// check if it is zero - i.e. possibly wrong
if ( ( $PI_tag_count == 0 ) )
{
// Tag count is zero - try moving the position by one,
// then re-extracting the count
$count_pos++;
$PI_tag_count = get_IFD_Data_Type( substr($tag['Data'], $count_pos, 2) , 3, $tag['Byte Align'] );
}
// Extract the data part of the PrintIM block
$data_part = substr($tag['Data'], $count_pos+2);
// Cycle through each tag
for ( $a = 0; $a < $PI_tag_count; $a++ )
{
// Read the tag number - 2 bytes
$PI_tag = get_IFD_Data_Type( substr($data_part, $a*6, 2) , 3, $tag['Byte Align'] );
// Read the tag data - 4 bytes
$newtag['Data'][ ] = array( 'Tag Number' => $PI_tag, 'Data' => substr($data_part, $a*6+2, 4) , 'Decoded' => False );
}
}
}
// Return the updated tag
return $newtag;
}
/******************************************************************************
* End of Function: Decode_PIM
******************************************************************************/
/******************************************************************************
*
* Function: Encode_PIM
*
* Description: Encodes the contents of a EXIF tag containing Print Image
* Matching information, and returns the contents as a packed binary string
*
* Parameters: tag - An EXIF tag containing Print Image Matching information
* as from get_EXIF_JPEG
* Byte_Align - the Byte alignment to use - "MM" or "II"
*
* Returns: packed_data - The packed binary string representing the PIM data
*
******************************************************************************/
function Encode_PIM( $tag, $Byte_Align)
{
// Create a string to receive the packed data
$packed_data = "";
// Check that this tag is for Print Image Matching Info
if ( $tag['Type'] == "PIM" )
{
// Check that the tag has been decoded - otherwise we don't need to do anything
if ( ( is_array( $tag['Data'] ) ) &&
( count ( $tag['Data'] ) > 0 ) )
{
// Add the header to the packed data
$packed_data .= "PrintIM\x00";
// Add the version to the packed data
$packed_data .= $tag['Data']['Version'] . "\x00";
// Create a string to receive the tag data
$tag_data_str = "";
// Cycle through each tag
$tag_count = 0;
foreach( $tag['Data'] as $key => $curr_tag )
{
// Make sure this is a tag and not supplementary info
if ( is_numeric( $key ) )
{
// Count how many tags are created
$tag_count++;
// Add the tag number to the packed tag data
$tag_data_str .= put_IFD_Data_Type( $curr_tag['Tag Number'], 3, $Byte_Align );
// Add the tag data to the packed tag data
$tag_data_str .= $curr_tag['Data'];
}
}
// Add the tag count to the packed data
$packed_data .= put_IFD_Data_Type( $tag_count, 3, $Byte_Align );
// Add the packed tag data to the packed data
$packed_data .= $tag_data_str;
}
}
// Return the resulting packed data
return $packed_data;
}
/******************************************************************************
* End of Function: Encode_PIM
******************************************************************************/
/******************************************************************************
*
* Function: get_PIM_Text_Value
*
* Description: Interprets the contents of a EXIF tag containing Print Image
* Matching information, and returns content as as a text string
*
* Parameters: tag - An EXIF tag containing Print Image Matching information
* as from get_EXIF_JPEG
* Tag_Definitions_Name - The name of the Tag Definitions group
* within the global array IFD_Tag_Definitions
*
* Returns: output_str - The text string representing the PIM info
*
******************************************************************************/
function get_PIM_Text_Value( $Tag, $Tag_Definitions_Name )
{
// Create a string to receive the output
$output_str = "";
// Check if the PIM tag has been decoded
if ( ( is_array( $Tag['Data'] ) ) &&
( count ( $Tag['Data'] ) > 0 ) )
{
// The tag has been decoded
// Add the Version to the output
$output_str = "Version: " . $Tag['Data']['Version'] . "\n";
// Check if the user wants to hide unknown tags
if ( $GLOBALS['HIDE_UNKNOWN_TAGS'] == FALSE )
{
// The user wants to see unknown tags
// Cycle through each tag
foreach ( $Tag['Data'] as $PIM_tag_Key => $PIM_tag )
{
// Check that the tag is not the version array element
if ( $PIM_tag_Key !== 'Version' )
{
// Add the tag to the output
$output_str .= "Unknown Tag " . $PIM_tag['Tag Number'] . ": (" . strlen( $PIM_tag['Data'] ) . " bytes of data)\n";
}
}
}
}
// Return the output text
return $output_str;
}
/******************************************************************************
* End of Function: get_PIM_Text_Value
******************************************************************************/
?>