PHP code example of ycs77 / image-metadata

1. Go to this page and download the library: Download ycs77/image-metadata library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

ycs77 / image-metadata example snippets


$image = Image::fromFile($filename);

$headline = $image->getXmp()->getHeadline();
$camera = $image->getExif()->getCamera();
...

$image = Image::fromFile($filename);

$xmp = $image->getXmp();
$xmp->setHeadline('A test headline');
$xmp->setCaption('Caption');

$image->getIptc()->setCategory('Category');

$image->save();

$xmp = new Xmp;
$xmp->setHeadline('A headline')
...

$data = $xmp->getXml();

$xmp = new Xmp($data); // or Xmp::fromFile($filename)
$xmp->setHeadline('A headline');

$data = $xmp->getXml();

$xmp = new Xmp;
$xmp->setHeadline('A headline');
...

$image = Image::fromFile($filename);
$image->setXmp($xmp);

$image->save() // or $image->getBytes()

$jpeg = JPEG::fromFile('image.jpg');
$png = PNG::fromFile('image.png');

$data = ...

$jpeg = JPEG::fromString($data);
$jpeg->getXmp()->setHeadline('Test headline');

$jpeg->save('out.jpg'); // or $jpeg->getBytes();

$gd = imagecreate(100, 100);
$jpeg = JPEG::fromResource($gd);

$stream = fopen('...', 'r+');
$jpeg = JPEG::fromStream($stream);

$image = Image::fromFile($filename);
$headline = $image->getAggregate()->getHeadline();

$aggregate = $image->getAggregate();
$aggregate->setPriority(['exif', 'iptc', 'xmp']);

$aggregate->getHeadline(); // will now check EXIF first, then IPTC, then XMP

$aggregate->setPriority(['iptc', 'xmp']);
$aggregate->getHeadline(); // will only check IPTC and XMP

$image = Image::fromFile($filename);
$image->getAggregate()->setHeadline('Headline');

$image->save();

$image = ...
$gps = $image->getAggregateMeta()->getGPS(); // checks EXIF and XMP
// or $gps = $image->getExif()->getGPS();

$lat = $gps->getLatitude();

use Ycs77\ImageMetadata\Image;
use Ycs77\ImageMetadata\Metadata\Panorama\GPano;

$image = Image::fromFile($filename);
$image->getXmp()->setPanorama(function (GPano $gPano) {
    return $gPano
        ->projectionType()
        ->usePanoramaViewer(true)
        ->croppedAreaImageWidthPixels(8192)
        ->croppedAreaImageHeightPixels(4096)
        ->fullPanoWidthPixels(8192)
        ->fullPanoHeightPixels(4096)
        ->croppedAreaLeftPixels(0)
        ->croppedAreaTopPixels(0)
        ->stitchingSoftware('Your App Name');
});
$image->save();