Tuesday, May 24, 2016

Securing Logo Image

Sometime, you may want to secure a logo (image) on your user-interface to avoid some replacement.
In that case we can encode the image to a text-base code. To do that we need img2php class which can be downloaded from phpclasses.org or you can download it here (12.7kb including samples) 

Following are the example of steps after extracting the package:
1. write this script
<?php
require_once("img2php.class.php");
$t = new img2php;
$t->generate("images/"); //place image(s) in a subfolder
?>

2. run the script and the result should be similiar to this:
<?php
        
/**
 * gonximage class : Generated based on directory (images/)
 * 
 * @package 
 * @author Ben Yacoub Hatem <hatem@php.net>
 * @copyright Copyright (c) 2004
 * @version $Id$ - 2009-03-11 11:03:42 - gonximage.class.php
 * @access public
 **/
class gonximage{
    /**
     * Constructor
     * @access protected
     */
    function gonximage(){
        
    }
    
    /**
     * Return image based on it name
     * @access public
     * @return void 
     **/
    function getimage($img){
        switch($img){

            case "orchid_jpg": 
                gonximage::orchid_jpg();
            break;

        } // switch
    }
    function orchid_jpg() 
    {
        header("Content-type: image/jpg");
        header("Content-length: 3980");
        echo base64_decode(
/9j/4AAQSkZJRgABAgAAAQABAAD/4QDmRXhpZgAASUkqAAgAAAAFABIBAwAB.
AAAAAQAAADEBAgAcAAAASgAAADIBAgAUAAAAZgAAABMCAwABAAAAAQAAAGmH.
BAABAAAAegAAAAAAAABBQ0QgU3lzdGVtcyBEaWdpdGFsIEltYWdpbmcAMjAw.
OTowMToxMiAyMjoyOTo0MwAFAACQBwAEAAAAMDIyMJCSAgAEAAAANDE4AAKg.
BAABAAAAjAAAAAOgBAABAAAAtAAAAAWgBAABAAAAvAAAAAAAAAACAAEAAgAE.
AAAAUjk4AAIABwAEAAAAMDEwMAAAAAAAAAAA/8AAEQgAtACMAwEhAAIRAQMR.
Af/bAIQAEw0OEQ4MExEPERUUExcdMB8dGhodOyotIzBGPkpJRT5EQ05XcF9O.
UmpUQ0RhhGJqc3d9fn1LXYmTiHmScHt9eAEfISEsJixWLy9Wtnlneba2tra2.
tra2tra2tra2tra2tra2tra2tra2tra2tra2tra2tra2tra2tra2tra2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m2m0TnjJHcTXPeWYk0xU.
NaKQPAFYBNSYK0UF2/p4Dactv9Pb5ODThcRV22wXnlu1BR6vcz9TLPtU119q.
qQeo0ikdqdpRta5e/wCkhI+TgUh4qqKqtdF3wiExVN656FlNwXeE7D+1BSX7.
j7/SJxgmexivWrxtXGK5BEc4qQLbuL28RMznihu2SssIAOY8VAmK8BUm96YA.
IpIOK0ChOvZtyioZJCzAHFUekFX7o+eaIU1zYDltznuDgVFeGcCY5pgpXYCi.
FxhZNqRsZtxxk+KQ2yAjBzkLmnrF9LW5TL3SOcAYmgkXnS4zsBBZifx2pPya.
k2TtPtS97EQWJFIZXu1CaOaaaiXRJlh81J1NGGF9yC2QRg5NPF1P6gXnHMCg.
prlxVB2ruY9+AtSXAWPME5OaQHvt4oWEZPekPAYnFX2Rt06uYiyrEgfqbAFC.
c6OkV7kQKk8eDQqmc1J51igqQ0HWKZUSxWrUlqsRicHBqstssEqqz8UETWw9.
gseR4qJ7am0W7gUolz1/igbO4eKgJAN0e1Ux/wALYXtcutu94gCkJHADECh7.
VJ5hFBuM80J5uaGpDT7hRVF//9k=.
);
    }


}
?> 

3. copy and save the result above (for instance encode.class.php)
4. write a script to show the image (show.php):
<?php
include "encode.class.php";
$img = new gonximage();
$imgfile = "orchid_jpg";
$img->getimage($imgfile);
 ?>