Search moodle.org's
Developer Documentation

See Release Notes

  • Bug fixes for general core bugs in 3.11.x will end 14 Nov 2022 (12 months plus 6 months extension).
  • Bug fixes for security issues in 3.11.x will end 13 Nov 2023 (18 months plus 12 months extension).
  • PHP version: minimum PHP 7.3.0 Note: minimum PHP version has increased since Moodle 3.10. PHP 7.4.x is supported too.

Baking badges library.

Author: Yuliya Bozhko <yuliya.bozhko@totaralms.com>
Copyright: 2012 onwards Totara Learning Solutions Ltd {@link http://www.totaralms.com/}
License: http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
File Size: 177 lines (6 kb)
Included or required: 1 time
Referenced: 0 times
Includes or requires: 0 files

Defines 1 class

PNG_MetaDataHandler:: (3 methods):
  __construct()
  check_chunks()
  add_chunks()


Class: PNG_MetaDataHandler  - X-Ref

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);
__construct($contents)   X-Ref
Prepares file for handling metadata.
Verifies that this file is a valid PNG file.
Unpacks file chunks and reads them into an array.

param: string $contents File content as a string

check_chunks($type, $check)   X-Ref
Checks if a key already exists in the chunk of said type.
We need to avoid writing same keyword into file chunks.

param: string $type Chunk type, like iTXt, tEXt, etc.
param: string $check Keyword that needs to be checked.
return: boolean (true|false) True if file is safe to write this keyword, false otherwise.

add_chunks($type, $key, $value)   X-Ref
Adds a chunk with keyword and data to the file content.
Chunk is added to the end of the file, before IEND image trailer.

param: string $type Chunk type, like iTXt, tEXt, etc.
param: string $key Keyword that needs to be added.
param: string $value Currently an assertion URL that is added to an image metadata.
return: string $result File content with a new chunk as a string. Can be used in file_put_contents() to write to a file.