Professional Documents
Culture Documents
Downloads
Documentation
Get Involved
Help
Search
PHP 7.2.0 Release Candidate 2 Released
Getting Started
Introduction
A simple tutorial
Language Reference
Basic syntax
Types
Variables
Constants
Expressions
Operators
Control Structures
Functions
Classes and Objects
Namespaces
Errors
Exceptions
Generators
References Explained
Predefined Variables
Predefined Exceptions
Predefined Interfaces and Classes
Context options and parameters
Supported Protocols and Wrappers
Security
Introduction
General considerations
Installed as CGI binary
Installed as an Apache module
Session Security
Filesystem Security
Database Security
Error Reporting
Using Register Globals
User Submitted Data
Magic Quotes
Hiding PHP
Keeping Current
Features
HTTP authentication with PHP
Cookies
Sessions
Dealing with XForms
Handling file uploads
Using remote files
Connection handling
http://php.net/manual/es/function.exif-read-data.php 1/17
15/9/2017 PHP: exif_read_data - Manual
Function Reference
Affecting PHP's Behaviour
Audio Formats Manipulation
Authentication Services
Command Line Specific Extensions
Compression and Archive Extensions
Credit Card Processing
Cryptography Extensions
Database Extensions
Date and Time Related Extensions
File System Related Extensions
Human Language and Character Encoding Support
Image Processing and Generation
Mail Related Extensions
Mathematical Extensions
Non-Text MIME Output
Process Control Extensions
Other Basic Extensions
Other Services
Search Engine Extensions
Server Specific Extensions
Session Extensions
Text Processing
Variable and Type Related Extensions
Web Services
Windows Only Extensions
XML Manipulation
GUI Extensions
Keyboard Shortcuts
?
This help
j
Next menu item
k
Previous menu item
gp
Previous man page
gn
Next man page
G
Scroll to bottom
gg
Scroll to top
gh
Goto homepage
gs
Goto search
(current page)
/
Focus search box
http://php.net/manual/es/function.exif-read-data.php 2/17
15/9/2017 PHP: exif_read_data - Manual
exif_tagname
name
exif_imagetype
Manual de PHP
Referencia de funciones
Procesamiento y generacin de imgenes
Exif
Funciones de Exif
exif_read_data
(PHP 4 >= 4.2.0, PHP 5, PHP 7)
Descripcin
array exif_read_data ( string $filename [, string $sections = NULL [, bool $arrays = false [, bool $thumbnail
= false ]]] )
exif_read_data() lee las cabeceras EXIF desde un archivo de imagen JPEG o TIFF. De esta forma se puede
leer los meta-datos generados por cmaras digitales.
Las cabeceras EXIF tienden a estar presentes en imgenes JPEG/TIFF generadas por cmaras digitales, pero
desafortunadamente cada fabricante de cmaras digitales tiene una idea diferente de cmo etiquetar sus
imgenes, por lo que no siempre se puede contar con que una cabecera Exif especfica est presente.
Height y Width son computados de la misma forma que lo hace getimagesize() por lo que sus valores no
deben ser parte de ninguna cabecera devuelta. Tambin, html es una cadena de texto de alto/ancho para usar
dentro de un HTML normal.
Cuando una cabecera Exif contiene una nota de Copyright, puede contener ella misma dos valores. Como la
solucin es inconsistente en el estndar Exif 2.10, la seccin COMPUTED devolver las dos entradas
Copyright.Photographer y Copyright.Editor mientras que las secciones IFD0 contienen la matriz de bytes
con el carcter NULL que divide ambas entradas. O slo la primera entrada si el tipo de informacin era
errneo (el comportamiento normal de Exif). COMPUTED tambin contendr la entrada Copyright que es la
cadena del copyright original, o una lista separada por comas del copyright de la fotografa y del editor.
La etiqueta UserComment tiene el mismo problema que la etiqueta Copyright. Puede almacenar dos valores.
El primero es el que usa la codificacin, y el segundo es el valor mismo. Por lo que si la seccin IFD slo
contiene la codificacin o una matriz de bytes, la seccin COMPUTED almacenar la dos entradas
UserCommentEncoding y UserComment. La entrada UserComment est disponible en ambos casos por lo
que se debera usar con preferencia al valor de la seccin IFD0.
exif_read_data() tambin valida las etiquetas de informacin EXIF segn la especifiacin EXIF
( http://exif.org/Exif2-2.PDF, pgina 20).
Nota:
Windows Me/XP pueden borrar las cabeceras Exif cuando se conecta una cmara.
Parmetros
http://php.net/manual/es/function.exif-read-data.php 3/17
15/9/2017 PHP: exif_read_data - Manual
filename
sections
Es una lista separada por comas de las secciones que necesitan estar presentes en el archivo para
producir un array resultante. Si no se puede encontrar ninguna seccin el valor devuelto es FALSE.
thumbnail
Cuando se establece a TRUE se lee la miniatura misma. Si no, slo se lee la informacin etiquetada.
Valores devueltos
Devuelve un array asociativo donde los ndices de la matriz son los nombres de las cabeceras y los valores de
la matriz son los valores asociados con esas cabeceras. Si no se puede devolver informacin,
exif_read_data() devolver FALSE.
Historial de cambios
Versin Descripcin
Se puede leer toda la informacin IFD embebida incluidas matrices (devueltas como tales).
Tambin, el tamao de una miniatura embebida es devuelto en una submatriz THUMBNAIL, y
4.3.0
puede devolver miniaturas en formato TIFF. Adems, ya no hay una longitud mxima para los
valores devueltos (no mientras el lmite de memoria haya sido alcanzado)
Si PHP tiene soporte para mbstring, el comentario de usuario puede cambiar automticamente de
4.3.0 codificacin. Tambin, si el comentario de usuario utiliza la codificacin Unicode o JIS, esta
codificacin ser cambiada automticamente segn la configuracin inicial de exif en php.ini
Si la imagen contiene cualquier informacin IFD0, entonces COMPUTED contiene la entrada
ByteOrderMotorola la cul es 0 para el orden de byte little-endian (intel) y 1 para el orden de byte
4.3.0
big-endian (motorola). Tambin, COMPUTED y UserComment ya no contienen la primera entrada
de copyright si el tipo de informacin era errneo.
http://php.net/manual/es/function.exif-read-data.php 4/17
15/9/2017 PHP: exif_read_data - Manual
Ejemplos
<?php
echo "prueba1.jpg:<br />\n";
$exif = exif_read_data('pruebas/prueba1.jpg', 'IFD0');
echo $exif===false ? "No se encontr informacin de cabecera.
<br />\n" : "La imagen contiene cabeceras<br />\n";
Ver tambin
add a note
up
http://php.net/manual/es/function.exif-read-data.php 5/17
15/9/2017 PHP: exif_read_data - Manual
down
53
chadsmith729 at gmail dot com
4 years ago
When the new update came out from Apple for iOS6 it provided the ability for iPad, iPod, and
iPhones to be able to upload files from the device through Safari. Obviously this will open up an
array of implementations where at one point it was just not possible.
The issue comes when a photo is uploaded it will be dependent on the location of the "button" when
the photo was taken. Imagine if you will that you have your iPhone turned with the button at the
top and you take a photo. The photo when uploaded to your server might be "upside down".
The following code will ensure that all uploaded photos will be oriented correctly upon upload:
<?php
$image = imagecreatefromstring(file_get_contents($_FILES['image_upload']['tmp_name']));
$exif = exif_read_data($_FILES['image_upload']['tmp_name']);
if(!empty($exif['Orientation'])) {
switch($exif['Orientation']) {
case 8:
$image = imagerotate($image,90,0);
break;
case 3:
$image = imagerotate($image,180,0);
break;
case 6:
$image = imagerotate($image,-90,0);
break;
}
}
// $image now contains a resource with the image oriented correctly
?>
What you do with the image resource from there is entirely up to you.
I hope that this helps you identify and orient any image that's uploaded from an iPad, iPhone, or
iPod. Orientation for the photo is the key to knowing how to rotate it correctly.
up
down
6
Eion Robb
2 years ago
I was needing to use exif_read_data() to read out the orientation flag, only to find that the
webhost didn't have the exif extension available for use. Instead, I hacked up a regex that
worked fairly well as a replacement
<?php
$orientation = 1;
if (function_exists('exif_read_data')) {
$exif = exif_read_data($filename);
if (isset($exif['Orientation']))
$orientation = $exif['Orientation'];
} else if (preg_match('@\x12\x01\x03\x00\x01\x00\x00\x00(.)\x00\x00\x00@',
file_get_contents($filename), $matches)) {
$orientation = ord($matches[1]);
}
?>
up
down
http://php.net/manual/es/function.exif-read-data.php 6/17
15/9/2017 PHP: exif_read_data - Manual
1
iam at thatguy dot co dot za
3 years ago
I posted the original version of the function, but after using it for a while I discovered I
didn't do enough error checking.
I have re-factored it somewhat, and it now returns an empty array should it not be able to read
the image's exif. If it is able to, it will return the details it was able to retrieve. And this
should be without error.
I am suppressing errors, because if you pass it images which cannot parse, you will get a warning.
<?php
// Check if the variable is set and if the file itself exists before continuing
if ((isset($imagePath)) AND (file_exists($imagePath)))
{
// There are 2 arrays which contains the information we are after, so it's easier to state
them both
$exif_ifd0 = @read_exif_data($imagePath ,'IFD0' ,0);
$exif_exif = @read_exif_data($imagePath ,'EXIF' ,0);
// Model
if (@array_key_exists('Model', $exif_ifd0))
{
$return['model'] = $exif_ifd0['Model'];
}
// Exposure
if (@array_key_exists('ExposureTime', $exif_ifd0))
{
$return['exposure'] = $exif_ifd0['ExposureTime'];
}
// Aperture
if (@array_key_exists('ApertureFNumber', $exif_ifd0['COMPUTED']))
{
http://php.net/manual/es/function.exif-read-data.php 7/17
15/9/2017 PHP: exif_read_data - Manual
$return['aperture'] = $exif_ifd0['COMPUTED']['ApertureFNumber'];
}
// ISO
if (@array_key_exists('ISOSpeedRatings',$exif_exif))
{
$return['iso'] = $exif_exif['ISOSpeedRatings'];
}
}
}
# Return either an empty array, or the details which we were able to extrapolate.
return $return;
}
?>
up
down
1
darkain at darkain dot com
9 years ago
I wanted some quick and easy functions for computing the shutter speed and f-stop. I couldn't
find any anywhere, so I made some. It took some research :
<?php
function exif_get_float($value) {
$pos = strpos($value, '/');
if ($pos === false) return (float) $value;
$a = (float) substr($value, 0, $pos);
$b = (float) substr($value, $pos+1);
return ($b == 0) ? ($a) : ($a / $b);
}
function exif_get_shutter(&$exif) {
if (!isset($exif['ShutterSpeedValue'])) return false;
$apex = exif_get_float($exif['ShutterSpeedValue']);
$shutter = pow(2, -$apex);
if ($shutter == 0) return false;
if ($shutter >= 1) return round($shutter) . 's';
return '1/' . round(1 / $shutter) . 's';
}
function exif_get_fstop(&$exif) {
if (!isset($exif['ApertureValue'])) return false;
$apex = exif_get_float($exif['ApertureValue']);
$fstop = pow(2, $apex/2);
if ($fstop == 0) return false;
return 'f/' . round($fstop,1);
}
?>
up
down
1
mafo at mafo removethis dot sk
10 years ago
some cameras (most higher models) have position senzor (gyroskope?) and taking-position is wrote
in EXIF, here is simple script for automatic rotating images
http://php.net/manual/es/function.exif-read-data.php 8/17
15/9/2017 PHP: exif_read_data - Manual
<?php
$exif = exif_read_data($filename);
$ort = $exif['IFD0']['Orientation'];
switch($ort)
{
case 1: // nothing
break;
?>
<?php
// This function is used to determine the camera details for a specific image. It returns an array
with the parameters.
function cameraUsed($imagePath) {
http://php.net/manual/es/function.exif-read-data.php 9/17
15/9/2017 PHP: exif_read_data - Manual
// Check if the variable is set and if the file itself exists before continuing
if ((isset($imagePath)) and (file_exists($imagePath))) {
// There are 2 arrays which contains the information we are after, so it's easier to state
them both
$exif_ifd0 = read_exif_data($imagePath ,'IFD0' ,0);
$exif_exif = read_exif_data($imagePath ,'EXIF' ,0);
//error control
$notFound = "Unavailable";
// Make
if (@array_key_exists('Make', $exif_ifd0)) {
$camMake = $exif_ifd0['Make'];
} else { $camMake = $notFound; }
// Model
if (@array_key_exists('Model', $exif_ifd0)) {
$camModel = $exif_ifd0['Model'];
} else { $camModel = $notFound; }
// Exposure
if (@array_key_exists('ExposureTime', $exif_ifd0)) {
$camExposure = $exif_ifd0['ExposureTime'];
} else { $camExposure = $notFound; }
// Aperture
if (@array_key_exists('ApertureFNumber', $exif_ifd0['COMPUTED'])) {
$camAperture = $exif_ifd0['COMPUTED']['ApertureFNumber'];
} else { $camAperture = $notFound; }
// Date
if (@array_key_exists('DateTime', $exif_ifd0)) {
$camDate = $exif_ifd0['DateTime'];
} else { $camDate = $notFound; }
// ISO
if (@array_key_exists('ISOSpeedRatings',$exif_exif)) {
$camIso = $exif_exif['ISOSpeedRatings'];
} else { $camIso = $notFound; }
$return = array();
$return['make'] = $camMake;
$return['model'] = $camModel;
$return['exposure'] = $camExposure;
$return['aperture'] = $camAperture;
$return['date'] = $camDate;
$return['iso'] = $camIso;
return $return;
} else {
return false;
}
}
?>
http://php.net/manual/es/function.exif-read-data.php 10/17
15/9/2017 PHP: exif_read_data - Manual
<?php
$camera = cameraUsed("/img/myphoto.jpg");
echo "Camera Used: " . $camera['make'] . " " . $camera['model'] . "<br />";
echo "Exposure Time: " . $camera['exposure'] . "<br />";
echo "Aperture: " . $camera['aperture'] . "<br />";
echo "ISO: " . $camera['iso'] . "<br />";
echo "Date Taken: " . $camera['date'] . "<br />";
?>
If the image has been re-sized and the information is no longer available then you should receive
the following when echoing the same:
Some cameras do not capture all the information, for instance Blackberry phones do not record an
aperture, or iso and you will get Unavailable for those fields.
$exif_['IFD0']['Title']=mb_convert_encoding($exif_['IFD0']['Title'],"auto","byte2le");
//
// outputs all available character encodings and prints on screen
// foreach(mb_list_encodings() as $chr)
http://php.net/manual/es/function.exif-read-data.php 11/17
15/9/2017 PHP: exif_read_data - Manual
// {$test[$chr]=mb_convert_encoding($image[IFD0][Title],'auto',$chr);}
// exit(print_r($test));
//
up
down
0
sakib dot farid at gmail dot com
2 years ago
Thanks to chadsmith729 at gmail dot com for the orientation fix.
I used this function for reading exif data from images. Turns out that if some metadata fields are
empty then the function reports unidentified tags with garbage data.
<?php
function CreateThumbnail($pic,$thumb,$thumbwidth, $quality = 100)
{
$im1=ImageCreateFromJPEG($pic);
//if(function_exists("exif_read_data")){
$exif = exif_read_data($pic);
if(!empty($exif['Orientation'])) {
switch($exif['Orientation']) {
case 8:
$im1 = imagerotate($im1,90,0);
break;
case 3:
$im1 = imagerotate($im1,180,0);
break;
case 6:
$im1 = imagerotate($im1,-90,0);
break;
}
}
//}
$info = @getimagesize($pic);
http://php.net/manual/es/function.exif-read-data.php 12/17
15/9/2017 PHP: exif_read_data - Manual
$width = $info[0];
$w2=ImageSx($im1);
$h2=ImageSy($im1);
$w1 = ($thumbwidth <= $info[0]) ? $thumbwidth : $info[0] ;
$h1=floor($h2*($w1/$w2));
$im2=imagecreatetruecolor($w1,$h1);
imagecopyresampled ($im2,$im1,0,0,0,0,$w1,$h1,$w2,$h2);
$path=addslashes($thumb);
ImageJPEG($im2,$path,$quality);
ImageDestroy($im1);
ImageDestroy($im2);
}
?>
up
down
-1
Clive dot Moore at ma-design dot com
3 years ago
Following up on darkain at darkain dot com script for grabbing the ShutterSpeedValue from exif
data...
@http://php.net/manual/en/function.exif-read-data.php
I have found that the option shown for ShutterSppedValue, can also be ExposureTime in the exif
data.
Also the code as written provides a WRONG return, as the return is always 1 so you get 1/1sec.
Here is corrected code, or a version that corrects what is obviously not working after 5 years
since it was originally developed::
function exif_get_float($value) {
$pos = strpos($value, '/');
if ($pos === false) return (float) $value;
$a = (float) substr($value, 0, $pos);
$b = (float) substr($value, $pos+1);
return ($b == 0) ? ($a) : ($a / $b);
};
function exif_get_exposureTime(&$exif) {
if (!isset($exif['ExposureTime'])) return false;
$apex = exif_get_float($exif['ExposureTime']);
$shutter = 1/$apex;
// above 1 sec exposure time::
if ($shutter <= 1) return round($apex) . ' seconds';
<?php
$exif_data = exif_read_data ( $_FILES['photo']
$emake =$exif_data['Make'];
$emodel = $exif_data['Model'];
$eexposuretime = $exif_data['ExposureTime'];
$efnumber = $exif_data['FNumber'];
$eiso = $exif_data['ISOSpeedRatings'];
$edate = $exif_data['DateTime'];
?>
will work, I tried using the PEL library, and while pretty cool, I can't for the life understand
how to call some things, this is simpler if your system is pretty basic or if you're in a rush.
If you have time, try playing with PEL. It's not maintained at the moment though..
http://pel.sourceforge.net/
up
down
0
lincolnzsilva at gmail dot com
8 years ago
Get some EXIFs fields (easy way):
<?php
$exif_make = exif_read_data ( $_FILES['photo']['tmp_name'] ,'IFD0' ,0 );
$emake = $exif_make['Make'];
<?php
ini_set('exif.encode_unicode', 'UTF-8');
echo $exif['WINXP']['Title'];
?>
If you have some problem, (the function didnt return anything, like a blocking call) try this:
$file = './image.jpg';
getimagesize ( $file , $info);
$exif = array();
if (isset($info)) {
foreach($info as $key => $val) {
if ($key != 'APP1') { $exif = read_exif_data($file); break; }
}
}
-- Sharp
up
down
-1
wdierkes at 5dollarwhitebox dot org
10 years ago
Using the exif methods to read WINXP data returns unexpected results unless both exif and mbstring
are compiled statically. Please reference the following bug reports:
Bug #31980
Bug #23105
This cannot be fixed due to the fact that mbstring has been removed from PHP core (it has been
'unbundled') and the rest of core files and other extensions cannot use mbstring functionality
when it is compiled as a shared library (dll).
"
If exif is compiled statically (--enable-exif) and mbstring compiled as a DSO module (--enable-
mbstring=shared) then exif_read_data may only return a single character rather than the entire
string.
http://php.net/manual/es/function.exif-read-data.php 15/17
15/9/2017 PHP: exif_read_data - Manual
Compiling both exif and mbstring statically (--enable-exif --enable-mbstring) resolves the issue.
up
down
-5
kurt at mandella dot biz
4 years ago
Photos processed in Picasa often contain garbage data in the "MAKERNOTE" section and under
EXIF.MakerNote, (UTF8) like:
This can't be written to Blob in MySql. The following code removes the garbage tags.
if($exif['IFD0']['Software'] == "Picasa"){
if($key != "MAKERNOTE"){
foreach ($section as $name => $val){
if($name != 'MakerNote'){
$exifA[$key][$name] = $val;
}
}
$exifB[$key] = $exifA[$key];
}
}
$serialized_exif = serialize ($exifB);
}else{
$serialized_exif = serialize ($exif);
}
add a note
Funciones de Exif
exif_imagetype
exif_read_data
exif_tagname
name
exif_thumbnail
read_exif_data
http://php.net/manual/es/function.exif-read-data.php 16/17
15/9/2017 PHP: exif_read_data - Manual
http://php.net/manual/es/function.exif-read-data.php 17/17