Source for file PelEntryUndefined.php

Documentation is available at PelEntryUndefined.php

  1. <?php
  2.  
  3. /* PEL: PHP EXIF Library. A library with support for reading and
  4. * writing all EXIF headers in JPEG and TIFF images using PHP.
  5. *
  6. * Copyright (C) 2004 Martin Geisler <gimpster@users.sourceforge.net>
  7. *
  8. * This program is free software; you can redistribute it and/or modify
  9. * it under the terms of the GNU General Public License as published by
  10. * the Free Software Foundation; either version 2 of the License, or
  11. * (at your option) any later version.
  12. *
  13. * This program is distributed in the hope that it will be useful,
  14. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. * GNU General Public License for more details.
  17. *
  18. * You should have received a copy of the GNU General Public License
  19. * along with this program in the file COPYING; if not, write to the
  20. * Free Software Foundation, Inc., 59 Temple Place, Suite 330,
  21. * Boston, MA 02111-1307 USA
  22. */
  23.  
  24. /* PelEntryUndefined.php,v 1.5 2004/06/26 20:39:10 gimpster Exp */
  25.  
  26.  
  27. /**
  28. * Classes used to hold data for EXIF tags of format undefined.
  29. *
  30. * This file contains the base class {@link PelEntryUndefined} and
  31. * the subclasses {@link PelEntryUserComment} which should be used
  32. * to manage the {@link PelTag::USER_COMMENT} tag, and {@link }
  33. * PelEntryVersion} which is used to manage entries with version
  34. * information.
  35. *
  36. * @author Martin Geisler <gimpster@users.sourceforge.net>
  37. * @version 1.5
  38. * @date 2004/06/26 20:39:10
  39. * @license http://www.gnu.org/licenses/gpl.html GNU General Public
  40. * License (GPL)
  41. * @package PEL
  42. */
  43.  
  44. /**#@+ Required class definitions. */
  45. ('PelEntry.php');
  46. /**#@-*/ * Class for holding data of any kind.
  47. *
  48. * This class can hold bytes of undefined format.
  49. *
  50. * @author Martin Geisler <gimpster@users.sourceforge.net>
  51. * @package PEL
  52. */
  53. class PelEntryUndefined extends PelEntry {
  54.  
  55. /**
  56. * Make a new PelEntry that can hold undefined data.
  57. *
  58. * @param PelTag the tag which this entry represents. This
  59. * should be one of the constants defined in {@link PelTag},
  60. * e.g., {@link PelTag::SCENE_TYPE}, {@link }
  61. * PelTag::MAKER_NOTE} or any other tag with format {@link }
  62. * PelFormat::UNDEFINED}.
  63. *
  64. * @param string the data that this entry will be holding. Since
  65. * the format is undefined, no checking will be done on the data.
  66. */
  67. function __construct($tag, $data = '') {
  68. $this->tag = $tag;
  69. $this->format = PelFormat::UNDEFINED;
  70. self::setValue($data);
  71. }
  72.  
  73.  
  74. /**
  75. * Set the data of this undefined entry.
  76. *
  77. * @param string the data that this entry will be holding. Since
  78. * the format is undefined, no checking will be done on the data.
  79. */
  80. function setValue($data) {
  81. $this->components = strlen($data);
  82. $this->bytes = $data;
  83. }
  84.  
  85.  
  86. /**
  87. * Get the data of this undefined entry.
  88. *
  89. * @return string the data that this entry is holding.
  90. */
  91. function getValue() {
  92. return $this->bytes;
  93. }
  94.  
  95.  
  96. /**
  97. * Get the value of this entry as text.
  98. *
  99. * The value will be returned in a format suitable for presentation.
  100. *
  101. * @param boolean some values can be returned in a long or more
  102. * brief form, and this parameter controls that.
  103. *
  104. * @return string the value as text.
  105. */
  106. function getText($brief = false) {
  107. switch ($this->tag) {
  108. case PelTag::FILE_SOURCE:
  109. //CC (e->components, 1, v);
  110. switch (ord($this->bytes{0})) {
  111. case 0x03:
  112. return 'DSC';
  113. default:
  114. return sprintf('0x%02X', ord($this->bytes{0}));
  115. }
  116. case PelTag::SCENE_TYPE:
  117. //CC (e->components, 1, v);
  118. switch (ord($this->bytes{0})) {
  119. case 0x01:
  120. return 'Directly photographed';
  121. default:
  122. return sprintf('0x%02X', ord($this->bytes{0}));
  123. }
  124. case PelTag::COMPONENTS_CONFIGURATION:
  125. //CC (e->components, 4, v);
  126. $v = '';
  127. for ($i = 0; $i < 4; $i++) {
  128. switch (ord($this->bytes{$i})) {
  129. case 0:
  130. $v .= '-';
  131. break;
  132. case 1:
  133. $v .= 'Y';
  134. break;
  135. case 2:
  136. $v .= 'Cb';
  137. break;
  138. case 3:
  139. $v .= 'Cr';
  140. break;
  141. case 4:
  142. $v .= 'R';
  143. break;
  144. case 5:
  145. $v .= 'G';
  146. break;
  147. case 6:
  148. $v .= 'B';
  149. break;
  150. default:
  151. $v .= 'reserved';
  152. break;
  153. }
  154. if ($i < 3) $v .= ' ';
  155. }
  156. return $v;
  157.  
  158. case PelTag::MAKER_NOTE:
  159. // TODO: handle maker notes.
  160. return $this->components . ' bytes unknown MakerNote data';
  161.  
  162. default:
  163. return '(undefined)';
  164. }
  165. }
  166.  
  167. }
  168.  
  169.  
  170. /**
  171. * Class for a user comment.
  172. *
  173. * This class is used to hold user comments, which can come in several
  174. * different character encodings. The EXIF standard specifies a
  175. * certain format of the {@link PelTag::USER_COMMENT user comment}
  176. * tag}, and this class will make sure that the format is kept.
  177. *
  178. * The most basic use of this class simply stores an ASCII encoded
  179. * string for later retrieval using {@link getValue}:
  180. *
  181. * <code>
  182. * $entry = new PelEntryUserComment('An ASCII string');
  183. * echo $entry->getValue();
  184. * </code>
  185. *
  186. * The string can be encoded with a different encoding, and if so, the
  187. * encoding must be given using the second argument. The EXIF
  188. * standard specifies three known encodings: 'ASCII', 'JIS', and
  189. * 'Unicode'. If the user comment is encoded using a character
  190. * encoding different from the tree known encodings, then the empty
  191. * string should be passed as encoding, thereby specifying that the
  192. * encoding is undefined.
  193. *
  194. * @author Martin Geisler <gimpster@users.sourceforge.net>
  195. * @package PEL
  196. */
  197. class PelEntryUserComment extends PelEntryUndefined {
  198.  
  199. /**
  200. * The user comment.
  201. *
  202. * @var string
  203. */
  204. private $comment;
  205.  
  206. /**
  207. * The encoding.
  208. *
  209. * This should be one of 'ASCII', 'JIS', 'Unicode', or ''.
  210. *
  211. * @var string
  212. */
  213. private $encoding;
  214.  
  215. /**
  216. * Make a new entry for holding a user comment.
  217. *
  218. * @param string the new user comment.
  219. *
  220. * @param string the encoding of the comment. This should be either
  221. * 'ASCII', 'JIS', 'Unicode', or the empty string specifying an
  222. * undefined encoding.
  223. */
  224. function __construct($comment = '', $encoding = 'ASCII') {
  225. parent::__construct(PelTag::USER_COMMENT);
  226. self::setValue($comment, $encoding);
  227. }
  228.  
  229. /**
  230. * Set the user comment.
  231. *
  232. * @param string the new user comment.
  233. *
  234. * @param string the encoding of the comment. This should be either
  235. * 'ASCII', 'JIS', 'Unicode', or the empty string specifying an
  236. * unknown encoding.
  237. */
  238. function setValue($comment = '', $encoding = 'ASCII') {
  239. $this->comment = $comment;
  240. $this->encoding = $encoding;
  241. parent::setValue(str_pad($encoding, 8, chr(0)) . $comment);
  242. }
  243.  
  244.  
  245. /**
  246. * Returns the user comment.
  247. *
  248. * The comment is returned with the same character encoding as when
  249. * it was set using {@link setValue} or {@link __construct the}
  250. * constructor}.
  251. *
  252. * @return string the user comment.
  253. */
  254. function getValue() {
  255. return $this->comment;
  256. }
  257.  
  258.  
  259. /**
  260. * Returns the encoding.
  261. *
  262. * @return string the encoding of the user comment.
  263. */
  264. function getEncoding() {
  265. return $this->encoding;
  266. }
  267.  
  268.  
  269. /**
  270. * Returns the user comment.
  271. *
  272. * @return string the user comment.
  273. */
  274. function getText($brief = false) {
  275. return $this->comment;
  276. }
  277.  
  278. }
  279.  
  280.  
  281. /**
  282. * Class to hold version information.
  283. *
  284. * There are three EXIF entries that hold version information: the
  285. * {@link PelTag::EXIF_VERSION}, {@link }
  286. * PelTag::FLASH_PIX_VERSION}, and {@link }
  287. * PelTag::INTEROPERABILITY_VERSION} tags. This class manages
  288. * those tags.
  289. *
  290. * The class is used in a very straight-forward way:
  291. * <code>
  292. * $entry = new PelEntryVersion(PelTag::EXIF_VERSION, 2.2);
  293. * </code>
  294. * This creates an entry for an file complying to the EXIF 2.2
  295. * standard. It is easy to test for standards level of an unknown
  296. * entry:
  297. * <code>
  298. * if ($entry->getTag() == PelTag::EXIF_VERSION &&
  299. * $entry->getValue() > 2.0) {
  300. * echo 'Recent EXIF version.';
  301. * }
  302. * </code>
  303. *
  304. * @author Martin Geisler <gimpster@users.sourceforge.net>
  305. * @package PEL
  306. */
  307. class PelEntryVersion extends PelEntryUndefined {
  308.  
  309. /**
  310. * The version held by this entry.
  311. *
  312. * @var float
  313. */
  314. private $version;
  315.  
  316.  
  317. /**
  318. * Make a new entry for holding a version.
  319. *
  320. * @param PelTag the tag. This should be one of {@link }
  321. * PelTag::EXIF_VERSION}, {@link PelTag::FLASH_PIX_VERSION},
  322. * or {@link PelTag::INTEROPERABILITY_VERSION}.
  323. *
  324. * @param float the version. The size of the entries leave room for
  325. * exactly four digits: two digits on either side of the decimal
  326. * point.
  327. */
  328. function __construct($tag, $version = 0.0) {
  329. parent::__construct($tag);
  330. $this->setValue($version);
  331. }
  332.  
  333.  
  334. /**
  335. * Set the version held by this entry.
  336. *
  337. * @param float the version. The size of the entries leave room for
  338. * exactly four digits: two digits on either side of the decimal
  339. * point.
  340. */
  341. function setValue($version = 0.0) {
  342. $this->version = $version;
  343. $major = floor($version);
  344. $minor = ($version - $major)*100;
  345. parent::setValue(sprintf('%02.0f%02.0f', $major, $minor));
  346. }
  347.  
  348.  
  349. /**
  350. * Return the version held by this entry.
  351. *
  352. * @return float the version. This will be the same as the value
  353. * given to {@link setValue} or {@link __construct the}
  354. * constructor}.
  355. */
  356. function getValue() {
  357. return $this->version;
  358. }
  359.  
  360. /**
  361. * Return a text string with the version.
  362. *
  363. * @param boolean controls if the output should be brief. Brief
  364. * output omits the word 'Version' so the result is just 'Exif x.y'
  365. * instead of 'Exif Version x.y' if the entry holds information
  366. * about the EXIF version --- the output for FlashPix is similar.
  367. *
  368. * @return string the version number with the type of the tag,
  369. * either 'Exif' or 'FlashPix'.
  370. */
  371. function getText($brief = false) {
  372. $v = $this->version;
  373.  
  374. /* Versions numbers like 2.0 would be output as just 2 if we don't
  375. * add the '.0' ourselves. */
  376. if (floor($this->version) == $this->version)
  377. $v .= '.0';
  378.  
  379. switch ($this->tag) {
  380. case PelTag::EXIF_VERSION:
  381. if ($brief)
  382. return Pel::fmt('Exif %s', $v);
  383. else
  384. return Pel::fmt('Exif Version %s', $v);
  385. case PelTag::FLASH_PIX_VERSION:
  386. if ($brief)
  387. return Pel::fmt('FlashPix %s', $v);
  388. else
  389. return Pel::fmt('FlashPix Version %s', $v);
  390. case PelTag::INTEROPERABILITY_VERSION:
  391. if ($brief)
  392. return Pel::fmt('Interoperability %s', $v);
  393. else
  394. return Pel::fmt('Interoperability Version %s', $v);
  395. }
  396.  
  397. if ($brief)
  398. return $v;
  399. else
  400. return Pel::fmt('Version %s', $v);
  401. }
  402.  
  403. }
  404.  
  405. ?>

SourceForge.net Logo Documentation generated on Wed, 21 Jul 2004 19:13:07 +0200 by phpDocumentor 1.3.0RC3