Source for file PelEntryByte.php

Documentation is available at PelEntryByte.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, 2005, 2006  Martin Geisler.
  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., 51 Franklin St, Fifth Floor,
  21.  *  Boston, MA 02110-1301 USA
  22.  */
  23.  
  24. /* $Id: PelEntryByte.php 419 2006-02-20 16:22:36Z mgeisler $ */
  25.  
  26.  
  27. /**
  28.  * Classes used to hold bytes, both signed and unsigned.  The {@link }
  29.  * PelEntryWindowsString} class is used to manipulate strings in the
  30.  * format Windows XP needs.
  31.  *
  32.  * @author Martin Geisler <mgeisler@users.sourceforge.net>
  33.  * @version $Revision: 419 $
  34.  * @date $Date: 2006-02-20 17:22:36 +0100 (Mon, 20 Feb 2006) $
  35.  * @license http://www.gnu.org/licenses/gpl.html GNU General Public
  36.  *  License (GPL)
  37.  * @package PEL
  38.  */
  39.  
  40. /**#@+ Required class definitions. */
  41. require_once('PelEntryNumber.php');
  42. /**#@-*/
  43.  
  44.  
  45.  * Class for holding unsigned bytes.
  46.  *
  47.  * This class can hold bytes, either just a single byte or an array of
  48.  * bytes.  The class will be used to manipulate any of the Exif tags
  49.  * which has format {@link PelFormat::BYTE}.
  50.  *
  51.  * @author Martin Geisler <mgeisler@users.sourceforge.net>
  52.  * @package PEL
  53.  */
  54. class PelEntryByte extends PelEntryNumber {
  55.  
  56.   /**
  57.    * Make a new entry that can hold an unsigned byte.
  58.    *
  59.    * The method accept several integer arguments.  The {@link }
  60.    * getValue} method will always return an array except for when a
  61.    * single integer argument is given here.
  62.    *
  63.    * @param PelTag the tag which this entry represents.  This
  64.    *  should be one of the constants defined in {@link PelTag}
  65.    *  which has format {@link PelFormat::BYTE}.
  66.    *
  67.    * @param int $value... the byte(s) that this entry will represent.
  68.    *  The argument passed must obey the same rules as the argument to
  69.    *  {@link setValue}, namely that it should be within range of an
  70.    *  unsigned byte, that is between 0 and 255 (inclusive).  If not,
  71.    *  then a {@link PelOverflowException} will be thrown.
  72.    */
  73.   function __construct($tag /* $value... */{
  74.     $this->tag    = $tag;
  75.     $this->min    = 0;
  76.     $this->max    = 255;
  77.     $this->format = PelFormat::BYTE;
  78.  
  79.     $value func_get_args();
  80.     array_shift($value);
  81.     $this->setValueArray($value);
  82.   }
  83.  
  84.  
  85.   /**
  86.    * Convert a number into bytes.
  87.    *
  88.    * @param int the number that should be converted.
  89.    *
  90.    * @param PelByteOrder one of {@link PelConvert::LITTLE_ENDIAN} and
  91.    *  {@link PelConvert::BIG_ENDIAN}, specifying the target byte order.
  92.    *
  93.    * @return string bytes representing the number given.
  94.    */
  95.   function numberToBytes($number$order{
  96.     return chr($number);
  97.   }
  98.  
  99. }
  100.  
  101.  
  102. /**
  103.  * Class for holding signed bytes.
  104.  *
  105.  * This class can hold bytes, either just a single byte or an array of
  106.  * bytes.  The class will be used to manipulate any of the Exif tags
  107.  * which has format {@link PelFormat::BYTE}.
  108.  *
  109.  * @author Martin Geisler <mgeisler@users.sourceforge.net>
  110.  * @package PEL
  111.  */
  112. class PelEntrySByte extends PelEntryNumber {
  113.  
  114.   /**
  115.    * Make a new entry that can hold a signed byte.
  116.    *
  117.    * The method accept several integer arguments.  The {@link getValue}
  118.    * method will always return an array except for when a single
  119.    * integer argument is given here.
  120.    *
  121.    * @param PelTag the tag which this entry represents.  This
  122.    *  should be one of the constants defined in {@link PelTag}
  123.    *  which has format {@link PelFormat::BYTE}.
  124.    *
  125.    * @param int $value... the byte(s) that this entry will represent.
  126.    *  The argument passed must obey the same rules as the argument to
  127.    *  {@link setValue}, namely that it should be within range of a
  128.    *  signed byte, that is between -128 and 127 (inclusive).  If not,
  129.    *  then a {@link PelOverflowException} will be thrown.
  130.    */
  131.   function __construct($tag /* $value... */{
  132.     $this->tag    = $tag;
  133.     $this->min    = -128;
  134.     $this->max    = 127;
  135.     $this->format = PelFormat::SBYTE;
  136.  
  137.     $value func_get_args();
  138.     array_shift($value);
  139.     $this->setValueArray($value);
  140.   }
  141.  
  142.  
  143.   /**
  144.    * Convert a number into bytes.
  145.    *
  146.    * @param int the number that should be converted.
  147.    *
  148.    * @param PelByteOrder one of {@link PelConvert::LITTLE_ENDIAN} and
  149.    *  {@link PelConvert::BIG_ENDIAN}, specifying the target byte order.
  150.    *
  151.    * @return string bytes representing the number given.
  152.    */
  153.   function numberToBytes($number$order{
  154.     return chr($number);
  155.   }
  156.  
  157. }
  158.  
  159.  
  160. /**
  161.  * Class used to manipulate strings in the format Windows XP uses.
  162.  *
  163.  * When examining the file properties of an image in Windows XP one
  164.  * can fill in title, comment, author, keyword, and subject fields.
  165.  * Filling those fields and pressing OK will result in the data being
  166.  * written into the Exif data in the image.
  167.  *
  168.  * The data is written in a non-standard format and can thus not be
  169.  * loaded directly --- this class is needed to translate it into
  170.  * normal strings.
  171.  *
  172.  * It is important that entries from this class are only created with
  173.  * the {@link PelTag::XP_TITLE}{@link PelTag::XP_COMMENT}{@link }
  174.  * PelTag::XP_AUTHOR}, {@link PelTag::XP_KEYWORD}, and {@link }
  175.  * PelTag::XP_SUBJECT} tags.  If another tag is used the data will no
  176.  * longer be correctly decoded when reloaded with PEL. (The data will
  177.  * be loaded as an {@link PelEntryByte} entry, which isn't as useful.)
  178.  *
  179.  * This class is to be used as in
  180.  * <code>
  181.  * $entry = $ifd->getEntry(PelTag::XP_TITLE);
  182.  * print($entry->getValue());
  183.  * $entry->setValue('My favorite cat');
  184.  * </code>
  185.  *
  186.  * @author Martin Geisler <mgeisler@users.sourceforge.net>
  187.  * @package PEL
  188.  */
  189. class PelEntryWindowsString extends PelEntry {
  190.  
  191.   /**
  192.    * The string hold by this entry.
  193.    *
  194.    * This is the string that was given to the {@link __construct}
  195.    * constructor} or later to {@link setValue}, without any extra NULL
  196.    * characters or any such nonsense.
  197.    *
  198.    * @var string 
  199.    */
  200.   private $str;
  201.  
  202.  
  203.   /**
  204.    * Make a new PelEntry that can hold a Windows XP specific string.
  205.    *
  206.    * @param int the tag which this entry represents.  This should be
  207.    *  one of {@link PelTag::XP_TITLE}{@link PelTag::XP_COMMENT},
  208.    *  {@link PelTag::XP_AUTHOR}{@link PelTag::XP_KEYWORD}, and {@link }
  209.    *  PelTag::XP_SUBJECT} tags.  If another tag is used, then this
  210.    *  entry will be incorrectly reloaded as a {@link PelEntryByte}.
  211.    *
  212.    * @param string the string that this entry will represent.  It will
  213.    *  be passed to {@link setValue} and thus has to obey its
  214.    *  requirements.
  215.    */
  216.   function __construct($tag$str ''{
  217.     $this->tag    = $tag;
  218.     $this->format = PelFormat::BYTE;
  219.     $this->setValue($str);
  220.   }
  221.  
  222.  
  223.   /**
  224.    * Give the entry a new value.
  225.    *
  226.    * This will overwrite the previous value.  The value can be
  227.    * retrieved later with the {@link getValue} method.
  228.    *
  229.    * @param string the new value of the entry.  This should be use the
  230.    *  Latin-1 encoding and be given without any extra NULL characters.
  231.    */
  232.   function setValue($str{
  233.     $l strlen($str);
  234.  
  235.     $this->components = ($l 1);
  236.     $this->str        $str;
  237.     $this->bytes      = '';
  238.     for ($i 0$i $l$i++)
  239.       $this->bytes .= $str{$ichr(0x00);
  240.  
  241.     $this->bytes .= chr(0x00chr(0x00);
  242.   }
  243.  
  244.  
  245.   /**
  246.    * Return the string of the entry.
  247.    *
  248.    * @return string the string held, without any extra NULL
  249.    *  characters.  The string will be the same as the one given to
  250.    *  {@link setValue} or to the {@link __construct constructor}.
  251.    */
  252.   function getValue({
  253.     return $this->str;
  254.   }
  255.  
  256.  
  257.   /**
  258.    * Return the string of the entry.
  259.    *
  260.    * This methods returns the same as {@link getValue}.
  261.    *
  262.    * @param boolean not used.
  263.    *
  264.    * @return string the string held, without any extra NULL
  265.    *  characters.  The string will be the same as the one given to
  266.    *  {@link setValue} or to the {@link __construct constructor}.
  267.    */
  268.   function getText($brief false{
  269.     return $this->str;      
  270.   }
  271.  
  272. }
  273.  
  274. ?>

Documentation generated on Tue, 19 Dec 2006 01:08:19 +0100 by phpDocumentor 1.3.0 SourceForge.net Logo