PHP and XMP format: Create a Panorama 360/VR viewer in PHP and A-Frame
The Extensible Metadata Platform (XMP) is an ISO standard, originally created by Adobe Systems Inc., for the creation, processing and interchange of standardized and custom metadata for digital documents and data sets.
XMP standardizes a data model, a serialization format and core properties for the definition and processing of extensible metadata. It also provides guidelines for embedding XMP information into popular image, video and document file formats, such as JPEG and PDF, without breaking their readability by applications that do not support XMP. Therefore, the non-XMP metadata have to be reconciled with the XMP properties. Although metadata can alternatively be stored in a sidecar file, embedding metadata avoids problems that occur when metadata is stored separately.
When you make a 360 photo or panorama, you can processes the photo and presents it in an interactive viewer like the A-frame viewer. To recognize such photos upon upload, the script looks for camera-specific metadata found in photos taken using 360-ready cameras. This information is embedded in photo's XMP (Extensible Metadata Platform) and/or Exif (Exchangeable image file format) tags, and if you're sharing 360 photos or panos straight from cameras or smartphones, the script automatically does the right thing, identify the picture and show it with the right viewer. Panoramas taken with smartphones that have native panorama-capture support will be presented in an interactive viewer.
XMP data is literally embedded into the image file so can extract it with PHP's string-functions from the image file itself.
The following demonstrates this procedure using SimpleXML but every other XML API or even simple and clever string parsing may give you equal results:
$content = file_get_contents($image); $xmp_data_start = strpos($content, '<x:xmpmeta'); $xmp_data_end = strpos($content, '</x:xmpmeta>'); $xmp_length = $xmp_data_end - $xmp_data_start; $xmp_data = substr($content, $xmp_data_start, $xmp_length + 12); $xmp = simplexml_load_string($xmp_data);
You can identify the equirectangular images as 360/VR images. After you have identified the images you can show the equirectangular images in the A-Frame Viewer.
Please, note that:
XMP makes heavy use of XML namespaces, so you'll have to keep an eye on that when parsing the XMP data with some XML tools.
considering the possible size of image files, you'll perhaps not be able to use
file_get_contents() as this function loads the whole image into memory. Using
fopen() to open a file stream resource and checking chunks of data for the key-sequences
</x:xmpmeta> will significantly reduce the memory footprint.
(Thanks to wohaby and alt-17 for image permissions)
- PHP: Basic Introduction to Namespaces
- PHP 7.2 will be the first Programming Language to add Modern Cryptography to its Standard Library
- Php: How to extend the highlight_string function
- Install Apache, MariaDB and PHP7 on Ubuntu 16.04
- Mallorca's Ham
- Install Memcache in Ubuntu 16.04
- PHP Libraries For Summer 2016
- PHP7: Install PHP7 with NGINX and MEMCACHE in Ubuntu 14.04
- PHP:How To Upgrade to PHP 7 on Ubuntu 14.04
- Install HHVM + Nginx on Ubuntu 14.04
- PHP7: Guide and References to all the changes between version 5.x and 7 of PHP
- How To Install PHP7 On The Main OS's