Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to read Photo exif Information in PHP

2025-03-01 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/03 Report--

This article mainly shows you "how to read photo exif information in PHP", the content is easy to understand, clear, hope to help you solve doubts, the following let the editor lead you to study and learn "how to read photo exif information in PHP" this article.

First, let's learn what is the Exif information of the picture.

Exif is an image file format, and its data storage is exactly the same as the JPEG format. In fact, Exif format inserts digital photo information into the head of JPEG format, including various shooting conditions, such as aperture, shutter, white balance, ISO, focal length, date and time, as well as camera brand, model, color coding, sound recorded during shooting, global positioning system (GPS), thumbnails and so on. To put it simply, Exif=JPEG+ shooting parameters. Therefore, you can browse photos in Exif format using any image-viewing software that can view JPEG files, but not all graphics programs can handle Exif information.

The exif of reading photos is not necessary in many cases, but compared to some sites that discuss photography, it is particularly important to read the exif information of photos, such as the photography forum hummingbird.

Screenshot from the hummingbird forum, the red circle information part is the program to read the exif information of the photo. We download the picture to the local, use the light and shadow magic hand to open the picture to see its Exif information, when BG, in addition to light and shadow, there are many tools to view the Exif value of the picture.

All the values can be read correctly except that the lens value in the Exif message cannot be read.

Open the PHP module

By default, the PHP Exif information module for reading pictures is not enabled. We need to open this module first.

Mbstring support is required to enable the Exif module, so install mbstring first. The following is an example of the Linux environment. Other environments are similar.

Install the mbstring module

First of all, find the location of the php source package, enter ext/mbstring directly, and execute the following command to install it. The specific parameters depend on your environment.

[root@lee ext] # cd / data0/software/php/ext/mbstring

[root@lee mbstring] # / usr/local/webserver/php/bin/phpize

Configuring for:

PHP Api Version: 20090626

Zend Module Api No: 20090626

Zend Extension Api No: 220090626

[root@lee exif] #. / configure-with-php-config=/usr/local/webserver/php/bin/php-config

[root@lee mbstring] # make & & make install

Installing shared extensions: / usr/local/webserver/php/lib/php/extensions/no-debug-non-zts-20090626/

Installing header files: / usr/local/webserver/php/include/php/

[root@lee mbstring] #

After the installation, we can go to the extensions directory to see if the module exists. The presence indicates that the installation is successful.

[root@lee mbstring] # cd / usr/local/webserver/php/lib/php/extensions/no-debug-non-zts-20090626/

[root@lee no-debug-non-zts-20090626] # ll

The total dosage is 1880

-rwxr-xr-x. 1 root root 414405 June 12 2012 eaccelerator.so

-rwxr-xr-x. 1 root root 1091242 September 23 2011 imagick.so

-rwxr-xr-x. 1 root root 5285 February 20 15:07 mbstring.so

-rwxr-xr-x. 1 root root 246752 September 23 2011 memcache.so

-rwxr-xr-x. 1 root root 154252 September 23 2011 pdo_mysql.so

Install the exif module

Similar to installing the mbstring module, first find the location of the source code and cd into it and configure the installation, depending on your own environment.

[root@lee exif] # cd / data0/software/php-5.3.13/ext/exif

[root@lee exif] #. / configure-with-php-config=/usr/local/webserver/php/bin/php-config

[root@lee exif] # make & & make install

Installing shared extensions: / usr/local/webserver/php/lib/php/extensions/no-debug-non-zts-20090626/

[root@lee exif] #

Enter the extensions directory to verify that the installation is successful

[root@lee exif] # cd / usr/local/webserver/php/lib/php/extensions/no-debug-non-zts-20090626/

[root@lee no-debug-non-zts-20090626] # ll

The total dosage is 2036

-rwxr-xr-x. 1 root root 414405 June 12 2012 eaccelerator.so

-rwxr-xr-x. 1 root root 158554 February 20 15:25 exif.so

-rwxr-xr-x. 1 root root 1091242 September 23 2011 imagick.so

-rwxr-xr-x. 1 root root 5285 February 20 15:07 mbstring.so

-rwxr-xr-x. 1 root root 246752 September 23 2011 memcache.so

-rwxr-xr-x. 1 root root 154252 September 23 2011 pdo_mysql.so

[root@lee no-debug-non-zts-20090626] #

The exif.so module already exists.

Add modules in php.ini

Open php.ini and add the following two lines

The copy code is as follows:

Extension = "mbstring.so"

Extension = "exif.so"

And make sure that your extension_ dirt value is the same as the Installing shared extensions value prompted when you install the module, for example, when I install the module, I am prompted to have the location of my extensions

The copy code is as follows:

/ usr/local/webserver/php/lib/php/extensions/no-debug-non-zts-20090626/

Then the extension_dir in your php.ini should point to the correct directory

The copy code is as follows:

Extension_dir= "/ usr/local/webserver/php/lib/php/extensions/no-debug-non-zts-20090626/"

Save php.ini and restart webserver.

Open phpinfo () and find the appropriate property to see if it is working properly.

Normally you will see the following two module messages

Use exif_read_data () to read the exif information of a picture

The image types that support reading exif information are already specified in phpinfo, and can only be jpeg or tiff types, where jpeg is a common type, which is sufficient.

Let's take a look at the user manual of the exif_read_data () function.

The copy code is as follows:

Array exif_read_data (string $filename [, string $sections = NULL [, bool $arrays = false [, bool $thumbnail = false])

Parameters:

Filename: the path of the image to read the exif information of the image. This cannot be URL.

Sections: is a comma-separated list of sections that need to exist in the file to produce an array of results. If the requested section is not found, the return value is FALSE.

FILEFileName, FileSize, FileDateTime, SectionsFoundCOMPUTEDhtml,Width,Height,IsColor, there may be more. Height and Width are calculated in the same way as getimagesize (), so their values cannot be part of any returned header information. In addition, html is a height/width text string that can be used in normal HTML. ANY_TAG any information that contains tags, such as tag data for all IFD0 of IFD0,EXIF,...IFD0. This includes the image size and others in the standard image file. If THUMBNAIL has a second IFD, the file should contain thumbnails. All tag information about embedded thumbnails is stored in this area. Comment header information for COMMENTJPEG images. The EXIFEXIF section is a subarea of IFDO and contains more details about the image. Most of the content is related to digital cameras.

Arrays: specifies whether each segment becomes an array. Sections COMPUTED,THUMBNAIL and COMMENT sections always become arrays because they contain names that conflict with other sections.

Thumbnail: when set to TRUE, read the thumbnail itself. Otherwise, only the tag data is read.

Let's try reading the exif information of a picture.

The copy code is as follows:

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report