exif.php

来自「php 开发的内容管理系统」· PHP 代码 · 共 1,125 行 · 第 1/3 页

PHP
1,125
字号
<?php/** * @package MediaWiki * @subpackage Metadata * * @author 脝var Arnfj枚r冒 Bjarmason <avarab@gmail.com> * @copyright Copyright 漏 2005, 脝var Arnfj枚r冒 Bjarmason * @license http://www.gnu.org/copyleft/gpl.html GNU General Public License * * This program 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. * * This program 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 this program; if not, write to the Free Software Foundation, Inc., * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. * http://www.gnu.org/copyleft/gpl.html * * @link http://exif.org/Exif2-2.PDF The Exif 2.2 specification * @bug 1555, 1947 *//** * @package MediaWiki * @subpackage Metadata */class Exif {	//@{	/* @var array	 * @private	 */	/**#@+	 * Exif tag type definition	 */	const BYTE      = 1;    # An 8-bit (1-byte) unsigned integer.	const ASCII     = 2;    # An 8-bit byte containing one 7-bit ASCII code. The final byte is terminated with NULL.	const SHORT     = 3;    # A 16-bit (2-byte) unsigned integer.	const LONG      = 4;    # A 32-bit (4-byte) unsigned integer.	const RATIONAL  = 5;    # Two LONGs. The first LONG is the numerator and the second LONG expresses the denominator	const UNDEFINED = 7;    # An 8-bit byte that can take any value depending on the field definition	const SLONG     = 9;    # A 32-bit (4-byte) signed integer (2's complement notation),	const SRATIONAL = 10;   # Two SLONGs. The first SLONG is the numerator and the second SLONG is the denominator.	/**	 * Exif tags grouped by category, the tagname itself is the key and the type	 * is the value, in the case of more than one possible value type they are	 * seperated by commas.	 */	var $mExifTags;	/**	 * A one dimentional array of all Exif tags	 */	var $mFlatExifTags;	/**	 * The raw Exif data returned by exif_read_data()	 */	var $mRawExifData;	/**	 * A Filtered version of $mRawExifData that has been pruned of invalid	 * tags and tags that contain content they shouldn't contain according	 * to the Exif specification	 */	var $mFilteredExifData;	/**	 * Filtered and formatted Exif data, see FormatExif::getFormattedData()	 */	var $mFormattedExifData;	//@}	//@{	/* @var string	 * @private	 */	/**	 * The file being processed	 */	var $file;	/**	 * The basename of the file being processed	 */	var $basename;	/**	 * The private log to log to	 */	var $log = 'exif';	//@}	/**	 * Constructor	 *	 * @param $file String: filename.	 */	function Exif( $file ) {		/**		 * Page numbers here refer to pages in the EXIF 2.2 standard		 *		 * @link http://exif.org/Exif2-2.PDF The Exif 2.2 specification		 */		$this->mExifTags = array(			# TIFF Rev. 6.0 Attribute Information (p22)			'tiff' => array(				# Tags relating to image structure				'structure' => array(					'ImageWidth' => Exif::SHORT.','.Exif::LONG,		# Image width					'ImageLength' => Exif::SHORT.','.Exif::LONG,	# Image height					'BitsPerSample' => Exif::SHORT,			# Number of bits per component					# "When a primary image is JPEG compressed, this designation is not"					# "necessary and is omitted." (p23)					'Compression' => Exif::SHORT,				# Compression scheme #p23					'PhotometricInterpretation' => Exif::SHORT,		# Pixel composition #p23					'Orientation' => Exif::SHORT,				# Orientation of image #p24					'SamplesPerPixel' => Exif::SHORT,			# Number of components					'PlanarConfiguration' => Exif::SHORT,			# Image data arrangement #p24					'YCbCrSubSampling' => Exif::SHORT,			# Subsampling ratio of Y to C #p24					'YCbCrPositioning' => Exif::SHORT,			# Y and C positioning #p24-25					'XResolution' => Exif::RATIONAL,			# Image resolution in width direction					'YResolution' => Exif::RATIONAL,			# Image resolution in height direction					'ResolutionUnit' => Exif::SHORT,			# Unit of X and Y resolution #(p26)				),				# Tags relating to recording offset				'offset' => array(					'StripOffsets' => Exif::SHORT.','.Exif::LONG,			# Image data location					'RowsPerStrip' => Exif::SHORT.','.Exif::LONG,			# Number of rows per strip					'StripByteCounts' => Exif::SHORT.','.Exif::LONG,			# Bytes per compressed strip					'JPEGInterchangeFormat' => Exif::SHORT.','.Exif::LONG,		# Offset to JPEG SOI					'JPEGInterchangeFormatLength' => Exif::SHORT.','.Exif::LONG,	# Bytes of JPEG data				),				# Tags relating to image data characteristics				'characteristics' => array(					'TransferFunction' => Exif::SHORT,		# Transfer function					'WhitePoint' => Exif::RATIONAL,		# White point chromaticity					'PrimaryChromaticities' => Exif::RATIONAL,	# Chromaticities of primarities					'YCbCrCoefficients' => Exif::RATIONAL,	# Color space transformation matrix coefficients #p27					'ReferenceBlackWhite' => Exif::RATIONAL	# Pair of black and white reference values				),				# Other tags				'other' => array(					'DateTime' => Exif::ASCII,            # File change date and time					'ImageDescription' => Exif::ASCII,    # Image title					'Make' => Exif::ASCII,                # Image input equipment manufacturer					'Model' => Exif::ASCII,               # Image input equipment model					'Software' => Exif::ASCII,            # Software used					'Artist' => Exif::ASCII,              # Person who created the image					'Copyright' => Exif::ASCII,           # Copyright holder				),			),			# Exif IFD Attribute Information (p30-31)			'exif' => array(				# Tags relating to version				'version' => array(					# TODO: NOTE: Nonexistence of this field is taken to mean nonconformance					# to the EXIF 2.1 AND 2.2 standards					'ExifVersion' => Exif::UNDEFINED,	# Exif version					'FlashpixVersion' => Exif::UNDEFINED, # Supported Flashpix version #p32				),				# Tags relating to Image Data Characteristics				'characteristics' => array(					'ColorSpace' => Exif::SHORT,		# Color space information #p32				),				# Tags relating to image configuration				'configuration' => array(					'ComponentsConfiguration' => Exif::UNDEFINED,		# Meaning of each component #p33					'CompressedBitsPerPixel' => Exif::RATIONAL,		# Image compression mode					'PixelYDimension' => Exif::SHORT.','.Exif::LONG,	# Valid image width					'PixelXDimension' => Exif::SHORT.','.Exif::LONG,	# Valind image height				),				# Tags relating to related user information				'user' => array(					'MakerNote' => Exif::UNDEFINED,			# Manufacturer notes					'UserComment' => Exif::UNDEFINED,			# User comments #p34				),				# Tags relating to related file information				'related' => array(					'RelatedSoundFile' => Exif::ASCII,			# Related audio file				),				# Tags relating to date and time				'dateandtime' => array(					'DateTimeOriginal' => Exif::ASCII,			# Date and time of original data generation #p36					'DateTimeDigitized' => Exif::ASCII,			# Date and time of original data generation					'SubSecTime' => Exif::ASCII,				# DateTime subseconds					'SubSecTimeOriginal' => Exif::ASCII,			# DateTimeOriginal subseconds					'SubSecTimeDigitized' => Exif::ASCII,			# DateTimeDigitized subseconds				),				# Tags relating to picture-taking conditions (p31)				'conditions' => array(					'ExposureTime' => Exif::RATIONAL,			# Exposure time					'FNumber' => Exif::RATIONAL,				# F Number					'ExposureProgram' => Exif::SHORT,			# Exposure Program #p38					'SpectralSensitivity' => Exif::ASCII,			# Spectral sensitivity					'ISOSpeedRatings' => Exif::SHORT,			# ISO speed rating					'OECF' => Exif::UNDEFINED,				# Optoelectronic conversion factor					'ShutterSpeedValue' => Exif::SRATIONAL,		# Shutter speed					'ApertureValue' => Exif::RATIONAL,			# Aperture					'BrightnessValue' => Exif::SRATIONAL,			# Brightness					'ExposureBiasValue' => Exif::SRATIONAL,		# Exposure bias					'MaxApertureValue' => Exif::RATIONAL,			# Maximum land aperture					'SubjectDistance' => Exif::RATIONAL,			# Subject distance					'MeteringMode' => Exif::SHORT,			# Metering mode #p40					'LightSource' => Exif::SHORT,				# Light source #p40-41					'Flash' => Exif::SHORT,				# Flash #p41-42					'FocalLength' => Exif::RATIONAL,			# Lens focal length					'SubjectArea' => Exif::SHORT,				# Subject area					'FlashEnergy' => Exif::RATIONAL,			# Flash energy					'SpatialFrequencyResponse' => Exif::UNDEFINED,	# Spatial frequency response					'FocalPlaneXResolution' => Exif::RATIONAL,		# Focal plane X resolution					'FocalPlaneYResolution' => Exif::RATIONAL,		# Focal plane Y resolution					'FocalPlaneResolutionUnit' => Exif::SHORT,		# Focal plane resolution unit #p46					'SubjectLocation' => Exif::SHORT,			# Subject location					'ExposureIndex' => Exif::RATIONAL,			# Exposure index					'SensingMethod' => Exif::SHORT,			# Sensing method #p46					'FileSource' => Exif::UNDEFINED,			# File source #p47					'SceneType' => Exif::UNDEFINED,			# Scene type #p47					'CFAPattern' => Exif::UNDEFINED,			# CFA pattern					'CustomRendered' => Exif::SHORT,			# Custom image processing #p48					'ExposureMode' => Exif::SHORT,			# Exposure mode #p48					'WhiteBalance' => Exif::SHORT,			# White Balance #p49					'DigitalZoomRatio' => Exif::RATIONAL,			# Digital zoom ration					'FocalLengthIn35mmFilm' => Exif::SHORT,		# Focal length in 35 mm film					'SceneCaptureType' => Exif::SHORT,			# Scene capture type #p49					'GainControl' => Exif::RATIONAL,			# Scene control #p49-50					'Contrast' => Exif::SHORT,				# Contrast #p50					'Saturation' => Exif::SHORT,				# Saturation #p50					'Sharpness' => Exif::SHORT,				# Sharpness #p50					'DeviceSettingDescription' => Exif::UNDEFINED,	# Desice settings description					'SubjectDistanceRange' => Exif::SHORT,		# Subject distance range #p51				),				'other' => array(					'ImageUniqueID' => Exif::ASCII,	# Unique image ID				),			),			# GPS Attribute Information (p52)			'gps' => array(				'GPSVersionID' => Exif::BYTE,			# GPS tag version				'GPSLatitudeRef' => Exif::ASCII,		# North or South Latitude #p52-53				'GPSLatitude' => Exif::RATIONAL,		# Latitude				'GPSLongitudeRef' => Exif::ASCII,		# East or West Longitude #p53				'GPSLongitude' => Exif::RATIONAL,		# Longitude				'GPSAltitudeRef' => Exif::BYTE,		# Altitude reference				'GPSAltitude' => Exif::RATIONAL,		# Altitude				'GPSTimeStamp' => Exif::RATIONAL,		# GPS time (atomic clock)				'GPSSatellites' => Exif::ASCII,		# Satellites used for measurement				'GPSStatus' => Exif::ASCII,			# Receiver status #p54				'GPSMeasureMode' => Exif::ASCII,		# Measurement mode #p54-55				'GPSDOP' => Exif::RATIONAL,			# Measurement precision				'GPSSpeedRef' => Exif::ASCII,			# Speed unit #p55				'GPSSpeed' => Exif::RATIONAL,			# Speed of GPS receiver				'GPSTrackRef' => Exif::ASCII,			# Reference for direction of movement #p55				'GPSTrack' => Exif::RATIONAL,			# Direction of movement				'GPSImgDirectionRef' => Exif::ASCII,		# Reference for direction of image #p56				'GPSImgDirection' => Exif::RATIONAL,		# Direction of image				'GPSMapDatum' => Exif::ASCII,			# Geodetic survey data used				'GPSDestLatitudeRef' => Exif::ASCII,		# Reference for latitude of destination #p56				'GPSDestLatitude' => Exif::RATIONAL,		# Latitude destination				'GPSDestLongitudeRef' => Exif::ASCII,		# Reference for longitude of destination #p57				'GPSDestLongitude' => Exif::RATIONAL,		# Longitude of destination				'GPSDestBearingRef' => Exif::ASCII,		# Reference for bearing of destination #p57				'GPSDestBearing' => Exif::RATIONAL,		# Bearing of destination				'GPSDestDistanceRef' => Exif::ASCII,		# Reference for distance to destination #p57-58				'GPSDestDistance' => Exif::RATIONAL,		# Distance to destination				'GPSProcessingMethod' => Exif::UNDEFINED,	# Name of GPS processing method				'GPSAreaInformation' => Exif::UNDEFINED,	# Name of GPS area				'GPSDateStamp' => Exif::ASCII,		# GPS date				'GPSDifferential' => Exif::SHORT,		# GPS differential correction			),		);		$this->file = $file;		$this->basename = basename( $this->file );		$this->makeFlatExifTags();		$this->debugFile( $this->basename, __FUNCTION__, true );		wfSuppressWarnings();		$data = exif_read_data( $this->file );		wfRestoreWarnings();		/**		 * exif_read_data() will return false on invalid input, such as		 * when somebody uploads a file called something.jpeg		 * containing random gibberish.		 */		$this->mRawExifData = $data ? $data : array();		$this->makeFilteredData();		$this->makeFormattedData();		$this->debugFile( __FUNCTION__, false );	}	/**#@+	 * @private	 */	/**	 * Generate a flat list of the exif tags	 */	function makeFlatExifTags() {		$this->extractTags( $this->mExifTags );	}	/**	 * A recursing extractor function used by makeFlatExifTags()	 *	 * Note: This used to use an array_walk function, but it made PHP5	 * segfault, see `cvs diff -u -r 1.4 -r 1.5 Exif.php`	 */	function extractTags( &$tagset ) {		foreach( $tagset as $key => $val ) {			if( is_array( $val ) ) {				$this->extractTags( $val );			} else {				$this->mFlatExifTags[$key] = $val;			}		}	}	/**	 * Make $this->mFilteredExifData	 */	function makeFilteredData() {		$this->mFilteredExifData = $this->mRawExifData;		foreach( $this->mFilteredExifData as $k => $v ) {			if ( !in_array( $k, array_keys( $this->mFlatExifTags ) ) ) {				$this->debug( $v, __FUNCTION__, "'$k' is not a valid Exif tag" );				unset( $this->mFilteredExifData[$k] );			}		}		foreach( $this->mFilteredExifData as $k => $v ) {			if ( !$this->validate($k, $v) ) {				$this->debug( $v, __FUNCTION__, "'$k' contained invalid data" );				unset( $this->mFilteredExifData[$k] );			}		}	}	/**	 * @todo document	 */	function makeFormattedData( ) {		$format = new FormatExif( $this->getFilteredData() );		$this->mFormattedExifData = $format->getFormattedData();	}	/**#@-*/	/**#@+	 * @return array	 */

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?