Join Up!
96814 members and counting!

 
downloads | documentation | faq | getting help | mailing lists | reporting bugs | php.net sites | links 
search for in the  
previousError HandlingHTTP authentication with PHPnext
Last updated: Tue, 28 May 2002
view the printer friendly version or the printer friendly version with notes

Luku 16. Creating and manipulating images

PHP is not limited to creating just HTML output. It can also be used to create and manipulate image files in a variety of different image formats, including gif, png, jpg, wbmp, and xpm. Even more convenient, php can output image streams directly to a browser. You will need to compile PHP with the GD library of image functions for this to work. GD and PHP may also require other libraries, depending on which image formats you want to work with. GD stopped supporting Gif images in version 1.6.

Esimerkki 16-1. PNG creation with PHP

<?php
    Header("Content-type: image/png");
    $string=implode($argv," ");
    $im = ImageCreateFromPng("images/button1.png");
    $orange = ImageColorAllocate($im, 220, 210, 60);
    $px = (imagesx($im)-7.5*strlen($string))/2;
    ImageString($im,3,$px,9,$string,$orange);
    ImagePng($im);
    ImageDestroy($im);
?>
This example would be called from a page with a tag like: <img src="button.php?text"> The above button.php script then takes this "text" string an overlays it on top of a base image which in this case is "images/button1.png" and outputs the resulting image. This is a very convenient way to avoid having to draw new button images every time you want to change the text of a button. With this method they are dynamically generated.

User Contributed Notes
Creating and manipulating images
add a note about notes
There are no user contributed notes for this page.
previousError HandlingHTTP authentication with PHPnext
Last updated: Tue, 28 May 2002
Copyright © 2001, 2002 The PHP Group
All rights reserved.
This mirror generously provided by: http://phpbuilder.com/
Last updated: Thu Oct 31 18:34:28 2002 EST