PHP Image: Embed Your Image to PHP Line Codes



PHP Image Tutorial: Usually, we put image in a directory. Then, we call by using tag <img src="/path/to/image">. We can see clearly location and name of the image file. In this post, We will talk how to hide image and emmbed to our php line code. So, we will not put image file to a directory. It is nice idea!

We need class named "img2php". You can download at phpclasses.org/img2php. After download, follow this steps:

  1. Extract zip file to specific directory, for example, www/test/img2php like following sceen.
    embed image to php code - prepare class file
  2. Create folder named "images" within www/test/img2php. Put some images file.
    embed image to php code - prepare images
  3. Create a file name "test.php" within www/test/img2php.
  4. Enter following code
     <?
     require_once("img2php.class.php");
     
     $t = new img2php;
     $t ->generate("images");
     ?>
    
  5. Point your browser to http://localhost/test/img2php/test.php. You will get like following screen:
    embed image to php code - code
  6. Create file named "test.class.php" within www/test/img2php. Enter code that you got from browser. Just copy all and paste.
  7. Last, we create page that load the image. Create a file named "test.show.php" within www/test/img2php. Enter following code:
     <?
     include "test.class.php";
     
     $img  = new gonximage();
     $name = "action_forward_gif";
     $img  ->getImage($name);
     
     ?>
    

Now, point your browser to http://localhost/test/img2php/test.show.php.

Happy New Year!




Tag: image, gd Category: PHP Classes Post : January 01st 2008 Read: 3,389 Bookmark and Share

blog comments powered by Disqus