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

What is the method of reading the EXIF information of a picture using PHP

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

Share

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

This article mainly explains "what is the method of using PHP to read the EXIF information of the picture". The content of the explanation in the article is simple and clear, and it is easy to learn and understand. please follow the editor's train of thought slowly and deeply, to study and learn "what is the method of using PHP to read the EXIF information of the picture".

In our photos and all kinds of image files, in fact, there are some information that can not be seen directly, such as the location information when the phone takes pictures, the type and size of the picture, and so on, which is called EXIF information. General JPG, TIFF and other picture files will have this kind of information. In fact, EXIF is specially tailored for this kind of digital photos, specially used to record the attribute information and shooting data of digital photos, originally developed by Japan. In fact, this is easy to understand. Japan basically monopolizes the camera industry, so of course this kind of standard is set by them!

EXIF has native support in the Windows system. Right-click the picture to open the menu, then click the properties and switch to the details to see the EXIF information of the picture file directly. Because this information can be edited at will, it can be used as a reference, but not as a definite value of some functional attributes, such as width and height, do not fully trust the information in EXIF.

Get picture type information in EXIF

First, let's take a look at the types of pictures we can see through EXIF.

Var_dump (exif_imagetype ($png)); / / int (3) echo exif_imagetype ($png) = = IMAGETYPE_PNG? $png. 'it 's a PNG picture': $png. Not a PNG picture, PHP_EOL;//.. / img/1.png is a PNG picture var_dump (exif_imagetype ($jpg)); / / int (2) echo exif_imagetype ($jpg) = = IMAGETYPE_JPEG? $jpg. 'it 's a jpg picture': $jpg. It's not a JPG picture. PHP_EOL;//.. / img/2.jpg is a jpg picture.

Using the exif_imagetype () function directly returns a constant of the image type, which is the image type represented by the constant information that begins with IMAGETYPE_. It also includes many other types, and this is just a demonstration of the acquisition of our most common image types, jpg and png.

It is the same as the third property returned by the getimagesize () function, that is, the property with subscript 2. In the getimagesize () function, 0 and 1 represent width and height, and 2 represents the type of picture.

Var_dump (getimagesize ($jpg)) / / array (7) {/ / [0] = > / / int (3) / / [1] = > / / int (2) / / [2] = > / / int (2) / / [3] = > / / string (24) "width=" 300 "height=" 244 "/ / [" bits "] = > / / int (8) / / [" channels "] = > / / Int (3) / / ["mime"] = > / / string (10) "image/jpeg" / /} get complete EXIF information

All the complete EXIF information in the picture is obtained through the exif_read_data () function.

Var_dump (exif_read_data ($png)); / / PHP Warning: exif_read_data (1.png): File not supported in / Users/zhangyue/MyDoc/ blog post / dev-blog/php/202011/source/11. Use PHP to get EXIF information for image files. Php on line 14 exif_read_data / Warning: exif_read_data (1.png): File not supported in / Users/zhangyue/MyDoc/ blog post / dev-blog/php/202011/source/11. Use PHP to get EXIF information for image files. Php on line 14 false / bool (false) var_dump (exif_read_data ($jpg)) / / array (8) {/ / ["FileName"] = > / / string (5) "2.jpg" / / ["FileDateTime"] = > / / int (1605061174) / / ["FileSize"] = > / / int (19075) / / ["FileType"] = > / / int (2) / /. / /.

As mentioned earlier, EXIF information only exists in JPG, TIFF and other image formats, so PNG images cannot get EXIF information. If you use exif_read_data () on a PNG picture, you will report a warning. In the case of JPG, the complete EXIF content is returned. Here we only intercept part of the content, not only width, height, type, compression ratio, etc., but also can see the phone manufacturer, geographical location, shutter parameters, aperture parameters, etc., of course, this also has a lot to do with the camera you use, some manufacturers may have less data. You can take a picture of yourself and then use this function to check it out for yourself.

In addition, there is an alias function read_exif_data (), which is similar to exif_read_data (), which is an alias and has been marked as out-of-date syntax since PHP7. You can learn more about it.

Var_dump (read_exif_data ($jpg)); / / PHP Deprecated: Function read_exif_data () is deprecated in / Users/zhangyue/MyDoc/ blog post / dev-blog/php/202011/source/11. Use PHP to get the EXIF information of the image file. Php on line 17 Function read_exif_data / Deprecated: Function read_exif_data () is deprecated in / Users/zhangyue/MyDoc/ blog post / dev-blog/php/202011/source/11. Use PHP to get the EXIF information of the image file. Php on line 17 FileName / array (8) {/ / ["FileName"] = > / / string (5) "2.jpg" / / ["FileDateTime"] = > / / int (1605061174) / / ["FileSize"] = > / /. / /. Gets the header name of the specified index

The index header corresponds to the field name in EXIF. We can view all the supported index header information, and there are a lot of contents. You can also get the attribute name according to the index header, and then look for the corresponding attribute information in EXIF.

Echo 256:. Exif_tagname (256). PHP_EOL;// 256: ImageWidthfor ($id = 1 $id / / string (6) "Xiaomi" / / ["THUMBNAIL"] = > / / array (9) {/ / ["JPEGInterchangeFormat"] = > / / int (5504) / / ["Orientation"] = > / / int (6) / / ["JPEGInterchangeFormatLength"] = > / / int (14369) / / [Compression "] = > / / int (6) / / ["ResolutionUnit"] = > / / int (2) / / ["XResolution"] = > / / string (4) "72int 1" / / ["YResolution"] = > / / string (4) "72int 1" / / ["ExifImageLength"] = > / / int (240) / / ["ExifImageWidth"] = > / / int (320) / / } / / ["UndefinedTag:0x9AAA"] = > / / string (4480) "1y / L" = w% / (4480) "1y / L" = w% /... / /. Thank you for your reading, the above is the content of "what is the method of using PHP to read the EXIF information of a picture". After the study of this article, I believe you have a deeper understanding of what is the method of reading EXIF information of a picture using PHP. The specific use of the situation also needs to be verified in practice. Here is, the editor will push for you more related knowledge points of the article, welcome to follow!

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