Results 1 to 4 of 4

Thread: Want to create Images in php ?

  1. #1
    Join Date
    Feb 2009
    Posts
    96

    Want to create Images in php ?

    hi,

    In php programming, what is the format of the code for creating images ? And how does the code work ?

    If anyone has the knowledge regarding this, then please give the relevant explanation.....thanks

  2. #2
    Join Date
    Apr 2008
    Posts
    1,948

    Re: Want to create Images in php ?

    PHP makes it very easy to do many things needed on a website, among which is to create an image. The ability to generate an image in PHP can be useful if you want to do things like create CAPTCHA images, or even design a banner or logo on the fly the way some free blogging software do.

    Creating Images in php requires
    Basic PHP Knowledge,
    Your PHP Must Have Been Compiled with the GD Library,
    FreeType Must Be Compiled for TrueType Font Support.

  3. #3
    Join Date
    Jan 2008
    Posts
    1,521

    Re: Want to create Images in php ?

    The easiest way to understand how to create an image is by looking at a sample code.

    Code:
    <?php
    $my_img = imagecreate( 200, 80 );
    $background = imagecolorallocate( $my_img, 0, 0, 255 );
    $text_colour = imagecolorallocate( $my_img, 255, 255, 0 );
    $line_colour = imagecolorallocate( $my_img, 128, 255, 0 );
    imagestring( $my_img, 4, 30, 25, "thesitewizard.com",
      $text_colour );
    imagesetthickness ( $my_img, 5 );
    imageline( $my_img, 30, 45, 165, 45, $line_colour );
    
    header( "Content-type: image/png" );
    imagepng( $my_img );
    imagecolordeallocate( $line_color );
    imagecolordeallocate( $text_color );
    imagecolordeallocate( $background );
    imagedestroy( $my_img );
    ?>
    The above code creates a 200x80 PNG image with a blue background and yellow text. It can be called from within your web page simply by referencing the php file.
    For example, if the PHP file that contains the above code is called myimage.php, then the HTML code to invoke it can simply be:

    <img src="myimpage.php" alt="Image created by a PHP script" width="200" height="80">

  4. #4
    Join Date
    May 2008
    Posts
    2,012

    Re: Want to create Images in php ?

    Some useful functions for creating images in php :

    imagecreate() - This function helps you to set dimensions of the image, namely its width and height in that order.

    imagecolorallocate() - This function helps you to collaborate colors. It will automatically fill the background of the image with the colour the first time you call it, as well as return an identifier for that particular colour. Subsequent calls to imagecolorallocate() will simply create a colour identifier for your colour, without affecting your image background.

    imagestring() - This function helps you to use a set of built-in fonts to do the writing.
    The second parameter specifies - the size of the font. The fonts have various sizes, ranging from 1 to 5, where 1 is the smallest font size and 5 the largest.
    The third and fourth parameters specifies the x,y coordinate for the top left hand corner of the text.
    The fifth parameter is for the text to print.
    The final parameter the colour of the text. This is the same colour that was allocated earlier using imagecolorallocate().

Similar Threads

  1. How to create ISO images for Solaris
    By Defender14 in forum Operating Systems
    Replies: 2
    Last Post: 16-07-2010, 12:33 PM
  2. How To Create Hyperlink Images
    By Vivan in forum Technology & Internet
    Replies: 6
    Last Post: 29-05-2010, 03:38 PM
  3. How to create Animated Images using JavaScript?
    By Rob Dizzle in forum Software Development
    Replies: 6
    Last Post: 24-03-2010, 09:49 PM
  4. How to create a 360 Degree Panorama images
    By Jacob in forum Windows Software
    Replies: 3
    Last Post: 08-09-2009, 09:48 AM
  5. ISO Recorder v3 : Create and Burn ISO images
    By Maximus() in forum Windows Software
    Replies: 4
    Last Post: 06-05-2009, 10:51 AM

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Page generated in 1,713,510,044.05586 seconds with 16 queries