PHP Classes

PHP Mx Gram: Encrypt and decrypt text messages inside PNG image

Recommend this page to a friend!
  Info   View files Example   Demos   Screenshots Screenshots   View files View files (6)   DownloadInstall with Composer Download .zip   Reputation   Support forum (1)   Blog    
Ratings Unique User Downloads Download Rankings
StarStarStarStar 74%Total: 208 All time: 8,359 This week: 196Up
Version License PHP version Categories
phpmxgram 1.0.0GNU General Publi...5PHP 5, Graphics, Cryptography


This class can encrypt and decrypt text messages inside PNG image.

It can take a text string, encrypts it with a given key and embeds it inside a given PNG image.

The class can also do the opposite, i.e. take a previously modified PNG image and extracts the encrypted text message that was previously embedded in it.

Innovation Award
PHP Programming Innovation award nominee
December 2017
Number 8
Some applications need to pass messages to people in a way that they can visually seem but nobody should be able to decode the messages.

This package can provide a solution for this problem by generating images that have their pixels set to a colors that encode the data of the messages to be passed.

Manuel Lemos
Picture of Luciano Salvino
  Performance   Level  
Name: Luciano Salvino <contact>
Classes: 11 packages by
Country: Argentina Argentina
Age: 50
All time rank: 134916 in Argentina Argentina
Week rank: 132 Up1 in Argentina Argentina Up
Innovation award
Innovation award
Nominee: 9x



> image processing

Encrypt and decrypt messages into a PNG image-code Accept multiples languages 2000 characters limit Only can read the messages users included in email friends list

See online demo on




  • [Luciano Salvino] - <>


To use the tools of this repo only has to be required in your composer.json:

      "lutian/PHPMxGram": "dev-master"

Use to encrypt message

require __DIR__ . '/PHPMxGram.php';

$mxGram = new \PHPMxGram\PHPMxGram();

// set uid and uid_token
// Define string
$string = 'Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.';
// Define dastination email list
$arrFriends = array('','','');
// define expiration time (ex: 24hs)
$expiration = (time() + (24 * 3600));

$arrData = array(
	"ownerId"     => $mxGram->getUserId(),
	"friends"     => $arrFriends,
	"message"     => $string,
	"date"        => date("Y-d-m H:i:s"),
	"expires"  	  => $expiration,
    "secure"      => microtime()

// convert data in json string
$jsonData = json_encode($arrData,TRUE);

// define imagePath
$imageFile = 'mxgram_demo_code.png';
$imagePath = realpath(dirname(__FILE__)).'/images/'.$imageFile;
// encrypt message
// create image-code
// show image
echo '<img src="images/'.$imageFile.'">';

Use to decrypt message

require __DIR__ . '/PHPMxGram.php';

$mxGram = new \PHPMxGram\PHPMxGram();

// define image path
$imageCode = realpath(dirname(__FILE__)).'/images/mxgram_demo_code.png';

// define email friend to match data friend list
$eachFriend = '';

// decrypt image-code
$data = $mxGram->decryptMedia($imageCode);
if(!empty($data)) {
	$arrData = json_decode($data,TRUE);
	$arrFriends = $arrData['friends'];
	$emailMatch = false;
	for($i=0;$i<count($arrFriends);$i++) {
		if(strtolower($eachFriend)==strtolower($arrFriends[$i])) $emailMatch = true;
	if(isset($eachFriend) && isset($arrData['friends']) && $emailMatch) {
		// show text if not expired yet
		if(isset($arrData['expires']) && ($arrData['expires'] == 0 || $arrData['expires'] > time())) {
			$textDecoded = $arrData['message'];
            $dateExpire = ($arrData['expires']>0?'<br>Message will expire on '.date("d/m/Y H:i:s",$arrData['expires']):'');
		} else {
			$text_decoded = 'Sorry, the message was expired';
			$dateExpire = '';
	} else {
		$textDecoded = 'Sorry, the message is not for you. Please try with another email.';
		$dateExpire = '';

} else {
    $textDecoded = 'Sorry, something is wrong with the image code. Try with another image code.';
	$dateExpire = '';

echo $textDecoded;
echo $dateExpire;



[Luciano Salvino]:

  • Decrypt2
  • Decrypt
  • Encrypt2
  • Encrypt
  Files folder image Files  
File Role Description
Files folder imageimages (1 file)
Accessible without login Plain text file composer.json Data Auxiliary data
Accessible without login Plain text file demo_decrypt.php Example Example script
Accessible without login Plain text file demo_encrypt.php Example Example script
Plain text file PHPMxGram.php Class Class source
Accessible without login Plain text file Doc. Documentation

  Files folder image Files  /  images  
File Role Description
  Accessible without login Image file mxgram_demo_code.png Icon Icon image

 Version Control Unique User Downloads Download Rankings  
This week:0
All time:8,359
This week:196Up
 User Ratings  
 All time