PHP code example of joserick / png-metadata

1. Go to this page and download the library: Download joserick/png-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/ */

    

joserick / png-metadata example snippets


// include composer autoload
etadata
use PNGMetadata\PNGMetadata;

// build PNGMetadata object with a image path.
$png_metadata = new PNGMetadata('Photo.png'); // return a 'ArrayObject' or 'Exception'

$png_metadata = PNGMetadata::extract('Photo.png'); // return a 'ArrayObject' or 'False'

$png_metadata = new PNGMetadata('Photo.png');
$metadata_array = $png_metadata->toArray(); // return simple 'Array'
//or
$metadata_array = PNGMetadata::extract('Photo.png')->toArray(); // return simple 'Array'

$png_metadata = new PNGMetadata('../Photo.png');
echo $png_metadata; // Print metadata in 2 colums.

$png_metadata = new PNGMetadata(___DIR___.'/Photo.png');
echo $png_metadata->get('exif:DateTime'); // Return a value, a array or false.

$png_metadata = new PNGMetadata('./Path/Photo.png');
// or
$png_metadata = PNGMetadata::extract('./Path/Photo.png');

foreach($png_metadata as $key => $value){
	echo $key . "<br>"; // Metadata types
}

$png_metadata = new PNGMetadata('../Photo.png');
// or
$png_metadata = PNGMetadata::extract('../Photo.png');

$thumb = $png_metadata->getThumbnail();

if ($thumb !== false) {
	header('Content-Type: image/png');
	imagepng($thumb);
	imagedestroy($thumb);
}

if (PNGMetadata::isPNG('./Photo_jpg.png')){
	echo 'Yes, it is a PNG.';
}else{
	echo 'No, it is not a PNG.'
}

return PNGMetadata::getType('./Photo') == 1 // GIF?