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

Documentation generated on Thu, 05 May 2011 07:19:03 +0200 by phpDocumentor 1.4.3