Moodle APIs 3.9
Moodle 3.9.13+ (Build: 20220325)
Public Member Functions | List of all members
PNG_MetaDataHandler Class Reference

Information on PNG file chunks can be found at http://www.w3.org/TR/PNG/#11Chunks Some other info on PNG that I used http://garethrees.org/2007/11/14/pngcrush/. More...

Public Member Functions

 __construct ($contents)
 Prepares file for handling metadata. More...
 
 add_chunks ($type, $key, $value)
 Adds a chunk with keyword and data to the file content. More...
 
 check_chunks ($type, $check)
 Checks if a key already exists in the chunk of said type. More...
 

Detailed Description

Information on PNG file chunks can be found at http://www.w3.org/TR/PNG/#11Chunks Some other info on PNG that I used http://garethrees.org/2007/11/14/pngcrush/.

Example of use: $png = new PNG_MetaDataHandler('file.png');

if ($png->check_chunks("tEXt", "openbadge")) { $newcontents = $png->add_chunks("tEXt", "openbadge", 'http://some.public.url/to.your.assertion.file'); }

file_put_contents('file.png', $newcontents);

Constructor & Destructor Documentation

◆ __construct()

PNG_MetaDataHandler::__construct (   $contents)

Prepares file for handling metadata.

Verifies that this file is a valid PNG file. Unpacks file chunks and reads them into an array.

Parameters
string$contentsFile content as a string

Member Function Documentation

◆ add_chunks()

PNG_MetaDataHandler::add_chunks (   $type,
  $key,
  $value 
)

Adds a chunk with keyword and data to the file content.

Chunk is added to the end of the file, before IEND image trailer.

Parameters
string$typeChunk type, like iTXt, tEXt, etc.
string$keyKeyword that needs to be added.
string$valueCurrently an assertion URL that is added to an image metadata.
Return values
string::$resultFile content with a new chunk as a string. Can be used in file_put_contents() to write to a file.
Exceptions
moodle_exceptionwhen unsupported chunk type is defined.

◆ check_chunks()

PNG_MetaDataHandler::check_chunks (   $type,
  $check 
)

Checks if a key already exists in the chunk of said type.

We need to avoid writing same keyword into file chunks.

Parameters
string$typeChunk type, like iTXt, tEXt, etc.
string$checkKeyword that needs to be checked.
Return values
boolean(true|false) True if file is safe to write this keyword, false otherwise.

The documentation for this class was generated from the following file: