unicodeToImage($str)
convert native unicode emoji directly to images
If you have native unicode emoji characters that you want to convert directly to images, you can use this function. It should be noted that once your input text has been converted to images it cannot be converted back using the provided functions.
For that reason, we recommend only converting input text to images when it's ready to display to the client. The better alternative, in our opinion, is to convert native unicode emoji to their corresponding shortname using toShort($str) for database storage.
Feel free to enter native unicode emoji in the input below to test the conversion process. For a complete list of emoji and their shortnames check out emoji.codes.
Note: Once you start dealing with native unicode characters server side, it's important to ensure that your web stack is set up to handle UTF-8 character encoding. That is outside of the scope of our demos, but a quick Google Search will guide you in the right direction.
Input:
Output:
unicodeToImage($_POST['inputText']);
}
?>
PHP Snippet:
As of version 1.4.1 this library method has new syntax.
<?php
namespace Emojione;
// include the PHP library (if not autoloaded)
require('./../lib/php/autoload.php');
$client = new Client(new Ruleset());
// ###############################################
// Optional:
// default is PNG but you may also use SVG
$client->imageType = 'svg'; // or png (default)
// if you want to host the images somewhere else
// you can easily change the default paths
$client->imagePathPNG = './../assets/png/'; // defaults to jsdelivr's free CDN
$client->imagePathSVG = './../assets/svg/'; // defaults to jsdelivr's free CDN
// ###############################################
if(isset($_POST['inputText'])) {
echo $client->unicodeToImage($_POST['inputText']);
}
?>
As of version 1.4.1 the following implementation has been deprecated. It's included in the library for backwards compatibility but will be removed at a later date.
<?php
// include the PHP library (if not autoloaded)
require('./../lib/php/autoload.php');
// ###############################################
// Optional:
// default is PNG but you may also use SVG
Emojione\Emojione::$imageType = 'svg'; // or png (default)
// if you want to host the images somewhere else
// you can easily change the default paths
Emojione\Emojione::$imagePathPNG = './../assets/png/'; // defaults to jsdelivr's free CDN
Emojione\Emojione::$imagePathSVG = './../assets/svg/'; // defaults to jsdelivr's free CDN
// ###############################################
if(isset($_POST['inputText'])) {
echo Emojione\Emojione::unicodeToImage($_POST['inputText']);
}
?>