PHPImage

Methods Summary
Methods __construct
You can create a new PHPImge object by 3 methods :
  1. This method is the simpliest but it doesn't create the drawing space.
    It can be usefull if you want to changes the default background color before creating the drawing space.
    $image = new PHPImage();
  2. This method create the image from an existing image file.
    The image format is the same as the file.
    $image = new PHPImage($my_existing_file);
  3. And this last method allow to create the object and its drawing space in one line (avoid calling create method after).
    $image = new PHPImage($width, $height);

alphablending
Aplhablending is an option which allow an automatic merge of colors and transparency during drawing.
If it is set to false, drawing doesn't take care of previous color during drawing.
This option this enabled by default.
$image = new PHPImage(200, 100);
$image->alphablending(true);
$image->alphablending(false);

cleanall
This method erase the whole image by recreating it.
$image->cleanall();

cleanat
This method erase the image from the specified point.
$image->cleanat($x, $y);

cleanrectangle
This method erase a rectangle part of the image.
$image->cleanrectangle($x1, $y1, $x2, $y2);

cleanrectanglewh
This method erase a rectangle part of the image.
$image->cleanrectanglewh($x1, $y1, $w, $h);

colorat
This method return a PHPImageColor objet of the specified position color.
$color = $image->colorat($x, $y);
echo 'R = '.$color->R.'
'; echo 'G = '.$color->G.'
'; echo 'B = '.$color->B.'
'; echo 'A = '.$color->A.'
';

convolution
Apply a convolution matrix on the image.
The matrix can be 3x3, 5x5 or 7x7.
Be carefull, this can use a lot of CPU.
  1. Syntax
    $image->convolution($matrix, $offset=0, $usealpha=false);
    
    $matrix   : values array or string of space separated values 
    $offset   : offset for all colors
    $usealpha : set to true to use the matrix on transparency
    
  2. Simple gaussian blur matrix.
    require(__DIR__.'/../../src/class.PHPImage.php');
    $matrix = '1 2 1  2 4 2  1 2 1';
    $image = new PHPImage('php.gif');
    $image->convolution($matrix);
    $image->format = 'png';
    $image->display();
  3. Same as previous but with blur on transparency.
    require(__DIR__.'/../../src/class.PHPImage.php');
    $matrix = '1 2 1  2 4 2  1 2 1';
    $image = new PHPImage('php.gif');
    $image->convolution($matrix, 0, true);
    $image->format = 'png';
    $image->display();
  4. Same as previous but with offset set.
    require(__DIR__.'/../../src/class.PHPImage.php');
    $matrix = array(array(1, 2, 1), array(2, 4, 2), array(1, 2, 1));
    $image = new PHPImage('php.gif');
    $image->convolution($matrix, 80, true);
    $image->format = 'png';
    $image->display();

copy
Copy an other image on the current image.
Each parameter can receive an integer or a percentage.
  1. Syntax
    copy(& $src, $dstx=0, $dsty=0, $srcx=0, $srcy=0, 
         $srcw=0, $srch=0, $alpha=-1, $dstpos='', $srcpos='')
    
    $src    : source image
    $dstx   : destination - X value
    $dsty   : destination - Y value
    $srcx   : source - X value
    $srcy   : source - Y value
    $srcw   : source width
    $srch   : source height
    $alpha  : transparency to apply
    $dstpos : destination position
    $srcpos : source position
    
  2. Simple copy without any parameters.
    require(__DIR__.'/../../src/class.PHPImage.php');
    $tux = new PHPImage('tux.gif');
    $image = new PHPImage('php.gif');
    $image->copy($tux);
    $image->format = 'png';
    $image->display();
  3. Copy of the entire image to a precise position.
    require(__DIR__.'/../../src/class.PHPImage.php');
    $tux = new PHPImage('tux.gif');
    $image = new PHPImage('php.gif');
    $image->copy($tux, 50, 20);
    $image->format = 'png';
    $image->display();
  4. Transparency application.
    require(__DIR__.'/../../src/class.PHPImage.php');
    $tux = new PHPImage('tux.gif');
    $image = new PHPImage('php.gif');
    // transparency: 50%
    
    $image->copy($tux, 50, 20, 0, 0, 0, 0, '50%');
    $image->format = 'png';
    $image->display();
  5. Copy of Tux's head.
    require(__DIR__.'/../../src/class.PHPImage.php');
    $tux = new PHPImage('tux.gif');
    $image = new PHPImage('php.gif');
    // point source : top center ('50%', 0)
    
    // position of point source : top center
    
    // width source : 50% of tux width
    
    // height source : 40% of tux height
    
    $image->copy($tux, 0, 0, '50%', 0, '50%', '40%', 0, '', 'top center');
    $image->format = 'png';
    $image->display();
  6. Copy to center bottom.
    require(__DIR__.'/../../src/class.PHPImage.php');
    $tux = new PHPImage('tux.gif');
    $image = new PHPImage('php.gif');
    $image->copy($tux, '50%', '100%', 0, 0, 0, 0, 0, 'center bottom');
    $image->format = 'png';
    $image->display();

copyresampled
Copy an other image on the current image and resize it correctly.
  1. Syntax
    copyresampled(& $src, $dstx=0, $dsty=0, $srcx=0, $srcy=0, $srcw=0, 
         $srch=0, $srcw=0, $srch=0, $alpha=-1, $dstpos='', $srcpos='')
    
    $src    : source image
    $dstx   : destination - X value
    $dsty   : destination - Y value
    $srcx   : source - X value
    $srcy   : source - Y value
    $dstw   : destination width
    $dsth   : destination height
    $srcw   : source width
    $srch   : source height
    $alpha  : transparency to apply
    $dstpos : destination position
    $srcpos : source position
    
  2. Simple copy without any parameters.
    require(__DIR__.'/../../src/class.PHPImage.php');
    $tux = new PHPImage('tux.gif');
    $image = new PHPImage('php.gif');
    $image->copyresampled($tux);
    $image->format = 'png';
    $image->display();
  3. Destination height at 50%.
    require(__DIR__.'/../../src/class.PHPImage.php');
    $tux = new PHPImage('tux.gif');
    $image = new PHPImage('php.gif');
    $image->copyresampled($tux, 0, 0, 0, 0, 0, '50%', 0, 0);
    $image->format = 'png';
    $image->display();

copyresampledfit
Copy an other image on the current image and resize it correctly keeping the ratio width/height.
  1. Syntax
    copyresampledfit(& $src, $dstx=0, $dsty=0, $srcx=0, $srcy=0, $srcw=0, 
         $srch=0, $srcw=0, $srch=0, $alpha=-1, $dstpos='', $srcpos='')
    
    $src    : source image
    $dstx   : destination - X value
    $dsty   : destination - Y value
    $srcx   : source - X value
    $srcy   : source - Y value
    $dstw   : destination width
    $dsth   : destination height
    $srcw   : source width
    $srch   : source height
    $alpha  : transparency to apply
    $dstpos : destination position
    $srcpos : source position
    
  2. Simple copy without any parameters.
    require(__DIR__.'/../../src/class.PHPImage.php');
    $tux = new PHPImage('tux.gif');
    $image = new PHPImage('php.gif');
    $image->copyresampledfit($tux);
    $image->format = 'png';
    $image->display();
  3. Destination height at 50%.
    require(__DIR__.'/../../src/class.PHPImage.php');
    $tux = new PHPImage('tux.gif');
    $image = new PHPImage('php.gif');
    $image->copyresampledfit($tux, 0, 0, 0, 0, 0, '50%', 0, 0);
    $image->format = 'png';
    $image->display();

copyresized
Copy an other image on the current image and resize it correctly (faster than copyresampled but less quality).
  1. Syntax
    copyresized(& $src, $dstx=0, $dsty=0, $srcx=0, $srcy=0, $srcw=0, 
         $srch=0, $srcw=0, $srch=0, $alpha=-1, $dstpos='', $srcpos='')
    
    $src    : source image
    $dstx   : destination - X value
    $dsty   : destination - Y value
    $srcx   : source - X value
    $srcy   : source - Y value
    $dstw   : destination width
    $dsth   : destination height
    $srcw   : source width
    $srch   : source height
    $alpha  : transparency to apply
    $dstpos : destination position
    $srcpos : source position
    
  2. Simple copy without any parameters.
    require(__DIR__.'/../../src/class.PHPImage.php');
    $tux = new PHPImage('tux.gif');
    $image = new PHPImage('php.gif');
    $image->copyresized($tux);
    $image->format = 'png';
    $image->display();
  3. Destination height at 50%.
    require(__DIR__.'/../../src/class.PHPImage.php');
    $tux = new PHPImage('tux.gif');
    $image = new PHPImage('php.gif');
    $image->copyresized($tux, 0, 0, 0, 0, 0, '50%', 0, 0);
    $image->format = 'png';
    $image->display();

copyresizedfit
Copy an other image on the current image and resize it correctly keeping the ratio width/height (faster than copyresampledfit but less quality).
  1. Syntax
    copyresizedfit(& $src, $dstx=0, $dsty=0, $srcx=0, $srcy=0, $srcw=0, 
         $srch=0, $srcw=0, $srch=0, $alpha=-1, $dstpos='', $srcpos='')
    
    $src    : source image
    $dstx   : destination - X value
    $dsty   : destination - Y value
    $srcx   : source - X value
    $srcy   : source - Y value
    $dstw   : destination width
    $dsth   : destination height
    $srcw   : source width
    $srch   : source height
    $alpha  : transparency to apply
    $dstpos : destination position
    $srcpos : source position
    
  2. Simple copy without any parameters.
    require(__DIR__.'/../../src/class.PHPImage.php');
    $tux = new PHPImage('tux.gif');
    $image = new PHPImage('php.gif');
    $image->copyresizedfit($tux);
    $image->format = 'png';
    $image->display();
  3. Destination height at 50%.
    require(__DIR__.'/../../src/class.PHPImage.php');
    $tux = new PHPImage('tux.gif');
    $image = new PHPImage('php.gif');
    $image->copyresizedfit($tux, 0, 0, 0, 0, 0, '50%', 0, 0);
    $image->format = 'png';
    $image->display();

create
This creates the drawing space defining width and height.
$image = new PHPImage();
$image->create(200, 100);

destroy
This destroys the drawing space and free memory.
Always remember to destroy images when you won't need them : it is good for the server.
$image = new PHPImage(200, 100);
// draw something

// ...

// and then

$image->destroy();

display
Return the image to the browser.
This method can also save the image in the same time.
It manages also a cache if needed.
  1. Simple display
    $image = new PHPImage();
    $image->create(200, 100);
    $image->display();
    
  2. Display and save the image to PNG format.
    $image = new PHPImage();
    $image->create(200, 100);
    $image->display('image.png');
    
  3. Display and save the image to JPG format with a precised quality.
    $image = new PHPImage();
    $image->create(200, 100);
    $image->display('image.jpg', 85); // quality: 0 to 100 (optional).
    
  4. Display with automatic cache.
    Note that the drawing space shouldn't be created before using display method in the if condition.
    If the image already exists and is valid (less than 10 minutes), then it displays the image and return true.
    $image = new PHPImage();
    $image->cachetime = 600; // 10 minutes
    if (!$image->display('image.jpg')) {
    	$image->create(200, 100);
    	$image->display('image.jpg');
    }
    

drawarc
Draw a circle part.
If line color, thickness or line style are not set, this will take the last values used.
  1. Syntax
    drawellipsearc($cx, $cy, $r, $start, $end, 
    	$linecolor='', $thickness=0, $linestyle='', $drawborders=false)
    
    $cx          : x center
    $cy          : y center
    $r           : radius
    $start       : start angle
    $end         : end angle
    $drawborders : draw the start and end lines
    $linecolor   : line color
    $thickness   : thickness
    $linestyle   : line style (solid, dot, square, dash, bigdash, double, triple)
    
  2. Example.
    require(__DIR__.'/../../src/class.PHPImage.php');
    $image = new PHPImage(120, 360);
    $blue = 'blue 30%';
    $red  = 'red 30%';
    
    $image->drawarc('50%', '50%', 50, 45, 225, 'green 60%', 15, 'double', false);
    $image->drawarc('50%', '50%', 30, -135, 45, 'green 60%', 15, 'dot', false);
    
    $image->drawarc('20%', '10%', 20, 100, 380, $blue, 1, 'solid', false);
    $image->drawarc('50%', '10%', 20, 100, 380, $blue, 1, 'square', false);
    $image->drawarc('80%', '10%', 20, 100, 380, $blue, 1, 'dot', false);
    $image->drawarc('25%', '25%', 20, 100, 380, $blue, 1, 'dash', false);
    $image->drawarc('75%', '25%', 20, 100, 380, $blue, 1, 'bigdash', false);
    
    $style = array(  // '' empty string means no color at all
    
    	$blue, $blue, $blue, $blue, $blue, $blue, $blue, $blue,
    	$blue, $blue, $blue, $blue, $blue, $blue, $blue, $blue,
    	''   , ''   , ''   , ''   , ''   , ''   , ''   , ''   ,
    	''   , ''   , ''   , ''   , ''   , ''   , ''   , ''   ,
    	$red , $red , $red , $red , $red , $red , $red , $red ,
    	$red , $red , $red , $red , $red , $red , $red , $red ,
    	''   , ''   , ''   , ''   , ''   , ''   , ''   , ''   ,
    	''   , ''   , ''   , ''   , ''   , ''   , ''   , ''   ,
    );
    $image->drawarc('50%', '50%', 20, 45, 225, '', 1, $style);
    
    $image->drawarc('10%', '75%', 20, -100, 100, $red, 5, 'solid', true);
    $image->drawarc('33%', '75%', 20, -100, 100, $red, 5, 'square', true);
    $image->drawarc('57%', '75%', 20, -100, 100, $red, 5, 'dot', true);
    $image->drawarc('80%', '75%', 20, -100, 100, $red, 5, 'dash', true);
    $image->drawarc('20%', '90%', 20, -100, 100, $red, 5, 'bigdash', true);
    $image->drawarc('50%', '90%', 20, -100, 100, $red, 5, 'double', true);
    $image->drawarc('80%', '90%', 20, -100, 100, $red, 5, 'triple', true);
    $image->format = 'png';
    $image->display();

drawcircle
Draw a circle.
If line color, thickness or line style are not set, this will take the last values used.
  1. Syntax
    drawellipse($cx, $cy, $r, $linecolor='', $thickness=0, $linestyle='')
    
    $cx        : x center
    $cy        : y center
    $r         : radius
    $linecolor : line color
    $thickness : thickness
    $linestyle : line style (solid, dot, square, dash, bigdash, double, triple)
    
  2. Example.
    require(__DIR__.'/../../src/class.PHPImage.php');
    $image = new PHPImage(120, 360);
    $blue = 'blue 30%';
    $red  = 'red 30%';
    
    $image->drawcircle('50%', '50%', '40%', 'green 60%', 15, 'double');
    $image->drawcircle('50%', '50%', '20%', 'green 60%', 15, 'dot');
    
    $image->drawcircle('25%', '10%', 20, $blue, 1, 'solid');
    $image->drawcircle('50%', '10%', 20, $blue, 1, 'square');
    $image->drawcircle('75%', '10%', 20, $blue, 1, 'dot');
    $image->drawcircle('33%', '25%', 20, $blue, 1, 'dash');
    $image->drawcircle('67%', '25%', 20, $blue, 1, 'bigdash');
    
    $style = array(  // '' empty string means no color at all
    
    	$blue, $blue, $blue, $blue, $blue, $blue, $blue, $blue,
    	$blue, $blue, $blue, $blue, $blue, $blue, $blue, $blue,
    	''   , ''   , ''   , ''   , ''   , ''   , ''   , ''   ,
    	''   , ''   , ''   , ''   , ''   , ''   , ''   , ''   ,
    	$red , $red , $red , $red , $red , $red , $red , $red ,
    	$red , $red , $red , $red , $red , $red , $red , $red ,
    	''   , ''   , ''   , ''   , ''   , ''   , ''   , ''   ,
    	''   , ''   , ''   , ''   , ''   , ''   , ''   , ''   ,
    );
    $image->drawcircle('50%', '50%', '20%', '', 1, $style);
    
    $image->drawcircle('20%', '75%', 20, $red, 5, 'solid');
    $image->drawcircle('40%', '75%', 20, $red, 5, 'square');
    $image->drawcircle('60%', '75%', 20, $red, 5, 'dot');
    $image->drawcircle('80%', '75%', 20, $red, 5, 'dash');
    $image->drawcircle('25%', '90%', 20, $red, 5, 'bigdash');
    $image->drawcircle('50%', '90%', 20, $red, 5, 'double');
    $image->drawcircle('75%', '90%', 20, $red, 5, 'triple');
    $image->format = 'png';
    $image->display();

drawellipse
Draw an ellipse.
If line color, thickness or line style are not set, this will take the last values used.
  1. Syntax
    drawellipse($cx, $cy, $w, $h, $linecolor='', $thickness=0, $linestyle='')
    
    $cx        : x center
    $cy        : y center
    $w         : width
    $h         : height
    $linecolor : line color
    $thickness : thickness
    $linestyle : line style (solid, dot, square, dash, bigdash, double, triple)
    
  2. Example.
    require(__DIR__.'/../../src/class.PHPImage.php');
    $image = new PHPImage(120, 360);
    $blue = 'blue 30%';
    $red  = 'red 30%';
    
    $image->drawellipse('50%', '50%', '90%', '90%', 'green 60%', 15, 'double');
    $image->drawellipse('50%', '50%', '50%', '50%', 'green 60%', 15, 'dot');
    
    $image->drawellipse('25%', '15%', 40, 50, $blue, 1, 'solid');
    $image->drawellipse('50%', '15%', 40, 50, $blue, 1, 'square');
    $image->drawellipse('75%', '15%', 40, 50, $blue, 1, 'dot');
    $image->drawellipse('33%', '35%', 40, 50, $blue, 1, 'dash');
    $image->drawellipse('67%', '35%', 40, 50, $blue, 1, 'bigdash');
    
    $style = array(  // '' empty string means no color at all
    
    	$blue, $blue, $blue, $blue, $blue, $blue, $blue, $blue,
    	$blue, $blue, $blue, $blue, $blue, $blue, $blue, $blue,
    	''   , ''   , ''   , ''   , ''   , ''   , ''   , ''   ,
    	''   , ''   , ''   , ''   , ''   , ''   , ''   , ''   ,
    	$red , $red , $red , $red , $red , $red , $red , $red ,
    	$red , $red , $red , $red , $red , $red , $red , $red ,
    	''   , ''   , ''   , ''   , ''   , ''   , ''   , ''   ,
    	''   , ''   , ''   , ''   , ''   , ''   , ''   , ''   ,
    );
    $image->drawellipse('50%', '50%', '90%', 20, '', 1, $style);
    
    $image->drawellipse('20%', '65%', 40, 50, $red, 5, 'solid');
    $image->drawellipse('40%', '65%', 40, 50, $red, 5, 'square');
    $image->drawellipse('60%', '65%', 40, 50, $red, 5, 'dot');
    $image->drawellipse('80%', '65%', 40, 50, $red, 5, 'dash');
    $image->drawellipse('25%', '85%', 40, 50, $red, 5, 'bigdash');
    $image->drawellipse('50%', '85%', 40, 50, $red, 5, 'double');
    $image->drawellipse('75%', '85%', 40, 50, $red, 5, 'triple');
    $image->format = 'png';
    $image->display();

drawellipsearc
Draw an ellipse part.
If line color, thickness or line style are not set, this will take the last values used.
  1. Syntax
    drawellipsearc($cx, $cy, $w, $h, $start, $end, 
    	$linecolor='', $thickness=0, $linestyle='', $drawborders=false)
    
    $cx          : x center
    $cy          : y center
    $w           : width
    $h           : height
    $start       : start angle
    $end         : end angle
    $drawborders : draw the start and end lines
    $linecolor   : line color
    $thickness   : thickness
    $linestyle   : line style (solid, dot, square, dash, bigdash, double, triple)
    
  2. Example.
    require(__DIR__.'/../../src/class.PHPImage.php');
    $image = new PHPImage(120, 360);
    $blue = 'blue 30%';
    $red  = 'red 30%';
    
    $image->drawellipsearc('50%', '50%', '90%', '90%', 40, 220, 'green 60%', 15, 'double', false);
    $image->drawellipsearc('50%', '50%', '50%', '50%', 40, 220, 'green 60%', 15, 'dot', false);
    
    $image->drawellipsearc('25%', '15%', 40, 50, 100, 380, $blue, 1, 'solid', false);
    $image->drawellipsearc('50%', '15%', 40, 50, 100, 380, $blue, 1, 'square', false);
    $image->drawellipsearc('75%', '15%', 40, 50, 100, 380, $blue, 1, 'dot', false);
    $image->drawellipsearc('33%', '35%', 40, 50, 100, 380, $blue, 1, 'dash', false);
    $image->drawellipsearc('67%', '35%', 40, 50, 100, 380, $blue, 1, 'bigdash', false);
    
    $style = array(  // '' empty string means no color at all
    
    	$blue, $blue, $blue, $blue, $blue, $blue, $blue, $blue,
    	$blue, $blue, $blue, $blue, $blue, $blue, $blue, $blue,
    	''   , ''   , ''   , ''   , ''   , ''   , ''   , ''   ,
    	''   , ''   , ''   , ''   , ''   , ''   , ''   , ''   ,
    	$red , $red , $red , $red , $red , $red , $red , $red ,
    	$red , $red , $red , $red , $red , $red , $red , $red ,
    	''   , ''   , ''   , ''   , ''   , ''   , ''   , ''   ,
    	''   , ''   , ''   , ''   , ''   , ''   , ''   , ''   ,
    );
    $image->drawellipsearc('50%', '50%', '90%', 20, -45, 225, '', 1, $style);
    
    $image->drawellipsearc('10%', '65%', 40, 50, -100, 100, $red, 5, 'solid', true);
    $image->drawellipsearc('33%', '65%', 40, 50, -100, 100, $red, 5, 'square', true);
    $image->drawellipsearc('57%', '65%', 40, 50, -100, 100, $red, 5, 'dot', true);
    $image->drawellipsearc('80%', '65%', 40, 50, -100, 100, $red, 5, 'dash', true);
    $image->drawellipsearc('25%', '85%', 40, 50, -100, 100, $red, 5, 'bigdash', true);
    $image->drawellipsearc('50%', '85%', 40, 50, -100, 100, $red, 5, 'double', true);
    $image->drawellipsearc('75%', '85%', 40, 50, -100, 100, $red, 5, 'triple', true);
    $image->format = 'png';
    $image->display();

drawfilledcircle
Draw a filled circle.
  1. Syntax
    drawfilledcircle($cx, $cy, $r, $color='')
    
    $cx    : x center
    $cy    : y center
    $r     : radius
    $color : filled color
    
  2. Example.
    require(__DIR__.'/../../src/class.PHPImage.php');
    $image = new PHPImage(120, 80);
    $image->drawfilledcircle('50%', '50%', 30, 'blue');
    $image->drawfilledcircle('17%', '50%', '40%', 'red 50%');
    $image->drawfilledcircle('83%', '50%', '20%', 'yellow 20%');
    $image->format = 'png';
    $image->display();

drawfilledcirclearc
Draw an arc filled circle.
  1. Syntax
    drawfilledcirclearc($cx, $cy, $r, $start, $end, $color='')
    
    $cx    : x center
    $cy    : y center
    $r     : radius
    $start : start angle
    $end   : end angle
    $color : filled color
    
  2. Example.
    require(__DIR__.'/../../src/class.PHPImage.php');
    $image = new PHPImage(120, 80);
    $image->drawfilledcirclearc('50%', '50%', '25%', -45, 180, 'blue');
    $image->drawfilledcirclearc('17%', '50%', '25%', -60, 90, 'red 50%');
    $image->drawfilledcirclearc('83%', '50%', '25%', 80, 10, 'yellow 20%');
    $image->format = 'png';
    $image->display();

drawfilledellipse
Draw a filled ellipse.
  1. Syntax
    drawfilledellipse($cx, $cy, $w, $h, $color='')
    
    $cx    : x center
    $cy    : y center
    $w     : width
    $h     : height
    $color : filled color
    
  2. Example.
    require(__DIR__.'/../../src/class.PHPImage.php');
    $image = new PHPImage(120, 80);
    $image->drawfilledellipse('50%', '50%', 50, 50, 'blue');
    $image->drawfilledellipse('17%', '50%', '45%', '110%', 'red 50%');
    $image->drawfilledellipse('83%', '50%', '60%', '30%', 'yellow 20%');
    $image->format = 'png';
    $image->display();

drawfilledellipsearc
Draw an arc filled ellipse.
  1. Syntax
    drawfilledellipsearc($cx, $cy, $w, $h, $start, $end, $color='')
    
    $cx    : x center
    $cy    : y center
    $w     : width
    $h     : height
    $start : start angle
    $end   : end angle
    $color : filled color
    
  2. Example.
    require(__DIR__.'/../../src/class.PHPImage.php');
    $image = new PHPImage(120, 80);
    $image->drawfilledellipsearc('50%', '50%', 50, 50, -45, 180, 'blue');
    $image->drawfilledellipsearc('17%', '50%', '45%', '110%', -60, 90, 'red 50%');
    $image->drawfilledellipsearc('83%', '50%', '60%', '30%', 80, 10, 'yellow 20%');
    $image->format = 'png';
    $image->display();

drawfilledpolygon
Draw a filled polygon.
  1. Syntax
    drawfilledpolygon($values, $fillcolor='')
    
    $values    : array of coordinates
    $fillcolor : fill color
    
  2. Example.
    require(__DIR__.'/../../src/class.PHPImage.php');
    $image = new PHPImage(120, 120);
    $form1 = array(
    	array(10, 10), array(100, 10), array(50, 50), array(100, 100),
    	array(30, 80), array(20, 50), array(40, 30),
    );
    $form2 = array(
    	array(20, 100), array(95, 40), array(15, 30), array(100, 80)
    );
    $form3 = array(
    	array(20, 105), array(30, 100), array(40, 110), array(50, 100),
    	array(60, 115), array(70, 105), array(80, 120), array(90, 110),
    	array(110, 110), array(110, 60), array(100, 70), array(95, 70), array(85, 60), 
    	array(40, 95), array(90, 105), array(40, 60), array(10, 80),
    );
    $image->drawfilledpolygon($form1, 'blue 30%');
    $image->drawfilledpolygon($form2, 'red 30%');
    $image->drawfilledpolygon($form3, 'green 30%');
    $image->format = 'png';
    $image->display();

drawfilledrectangle
Draw a rectangle.
If the fill color is not set, it will take the last value used.
  1. Syntax
    drawfilledrectangle($x1, $y1, $x2, $y2, $fillcolor='', $shapestyle='')
    
    $x1         : x point 1
    $y1         : y point 1
    $x2         : x point 2
    $y2         : y point 2
    $fillcolor  : line color
    $shapestyle : shape style (several values separated by spaces)
                  values syntax: '([%int], width[, height])'
                  corner : 'all',
    		               'tl' (top left),
    			    	   'tr' (top right),
    					   'bl' (bottom left),
    					   'br' (bottom right)
    			  shape  : 'biseau', 'biseau2', 'biseau3', 'biseau4',
    			           'round', 'round2',
    			           'curve', 'curve2', 'curve3', 'curve4', 'curve5', 'curve6',
    					   'trait', 'trait2', 'trait3',
    					   'empty', 'none'
    			  int    : hatching space (integer)
    
  2. Example.
    require(__DIR__.'/../../src/class.PHPImage.php');
    $image = new PHPImage(120, 180);
    $image->drawfilledrectangle(5, 5, 115, 35, 'red 20%', 'all(round, 10)');
    $image->drawfilledrectangle(20, 25, 100, 55, 'darkgreen 20%', 'all(curve, 10)');
    $image->drawfilledrectangle(35, 45, 85, 75, 'blue 20%', 'all(round2, 10)');
    $shape = 'tl(round, 20) tr(empty, 10, 20) bl(curve, 30, 20) br(biseau, 30)';
    $image->drawfilledrectangle(5, 80, 115, 175, 'blue', $shape);
    $image->drawfilledrectangle(15, 90, 105, 165, 'red', $shape);
    $shape = 'tl(round%3, 20) tr(empty, 10, 20) bl(curve%2, 30, 20) br(biseau%4, 30)';
    $image->drawfilledrectangle(25, 100, 95, 155, 'maroon', $shape);
    $shape = 'all(curve, 20, 10) tr(curve, 10, 20) bl(curve, 10, 20)';
    $image->drawfilledrectangle(45, 110, 75, 140, 'black', $shape);
    $image->format = 'png';
    $image->display();
  3. Shape styles.
    require(__DIR__.'/../../src/class.PHPImage.php');
    $image = new PHPImage(120, 280);
    $image->drawfilledrectangle(5, 5, 35, 35, 'black', 'all(none, 11)');
    $image->drawfilledrectangle(45, 5, 75, 35, 'blue', 'all(empty, 11)');
    $image->drawfilledrectangle(85, 5, 115, 35, 'red', 'all(biseau, 11)');
    
    $image->drawfilledrectangle(5, 45, 35, 75, 'black', 'all(biseau2, 11)');
    $image->drawfilledrectangle(45, 45, 75, 75, 'blue', 'all(biseau3, 11)');
    $image->drawfilledrectangle(85, 45, 115, 75, 'red', 'all(biseau4, 11)');
    
    $image->drawfilledrectangle(5, 85, 35, 115, 'black', 'all(round, 11)');
    $image->drawfilledrectangle(45, 85, 75, 115, 'blue', 'all(round2, 11)');
    $image->drawfilledrectangle(85, 85, 115, 115, 'red', 'all(curve, 11)');
    
    $image->drawfilledrectangle(5, 125, 35, 155, 'black', 'all(curve2, 11)');
    $image->drawfilledrectangle(45, 125, 75, 155, 'blue', 'all(curve3, 11)');
    $image->drawfilledrectangle(85, 125, 115, 155, 'red', 'all(curve4, 11)');
    
    $image->drawfilledrectangle(5, 165, 35, 195, 'black', 'all(curve5, 11)');
    $image->drawfilledrectangle(45, 165, 75, 195, 'blue', 'all(curve6, 11)');
    $image->drawfilledrectangle(85, 165, 115, 195, 'red', 'all(trait, 11)');
    
    $image->drawfilledrectangle(5, 205, 35, 235, 'black', 'all(trait2, 11)');
    $image->drawfilledrectangle(45, 205, 75, 235, 'blue', 'all(trait3, 11)');
    $image->drawfilledrectangle(85, 205, 115, 235, 'red', 'all(round2+curve, 11)');
    
    $image->drawfilledrectangle(5, 245, 35, 275, 'black', 'all(curve5+curve6, 11)');
    $image->drawfilledrectangle(45, 245, 75, 275, 'blue', 'all(round%2+round2, 11)');
    $image->drawfilledrectangle(85, 245, 115, 275, 'red', 'all(trait2+trait, 11)');
    $image->format = 'png';
    $image->display();

drawfilledrectanglewh
Draw a rectangle.
If the fill color is not set, it will take the last value used.
  1. Syntax
    drawfilledrectanglewh($x1, $y1, $w, $h, $fillcolor='', $shapestyle='')
    
    $x1         : x point 1
    $y1         : y point 1
    $w          : width
    $h          : height
    $fillcolor  : line color
    $shapestyle : shape style (several values separated by spaces)
                  values syntax: '([%int], width[, height])'
                  corner : 'all',
    		               'tl' (top left),
    			    	   'tr' (top right),
    					   'bl' (bottom left),
    					   'br' (bottom right)
    			  shape  : 'biseau', 'biseau2', 'biseau3', 'biseau4',
    			           'round', 'round2',
    			           'curve', 'curve2', 'curve3', 'curve4', 'curve5', 'curve6',
    					   'trait', 'trait2', 'trait3',
    					   'empty', 'none'
    			  int    : hatching space (integer)
    
  2. Example.
    require(__DIR__.'/../../src/class.PHPImage.php');
    $image = new PHPImage(120, 180);
    $image->drawfilledrectanglewh(5, 5, 110, 30, 'red 20%', 'all(round, 10)');
    $image->drawfilledrectanglewh(20, 25, 80, 30, 'darkgreen 20%', 'all(curve, 10)');
    $image->drawfilledrectanglewh(35, 45, 50, 30, 'blue 20%', 'all(round2, 10)');
    $shape = 'tl(round, 20) tr(empty, 10, 20) bl(curve, 30, 20) br(biseau, 30)';
    $image->drawfilledrectanglewh(5, 80, 110, 95, 'blue', $shape);
    $image->drawfilledrectanglewh(15, 90, 90, 75, 'red', $shape);
    $shape = 'tl(round%3, 20) tr(empty, 10, 20) bl(curve%2, 30, 20) br(biseau%4, 30)';
    $image->drawfilledrectanglewh(25, 100, 70, 55, 'maroon', $shape);
    $shape = 'all(curve, 20, 10) tr(curve, 10, 20) bl(curve, 10, 20)';
    $image->drawfilledrectanglewh(45, 110, 30, 30, 'black', $shape);
    $image->format = 'png';
    $image->display();
  3. Shape styles.
    require(__DIR__.'/../../src/class.PHPImage.php');
    $image = new PHPImage(120, 280);
    $image->drawfilledrectanglewh(5, 5, 30, 30, 'black', 'all(none, 11)');
    $image->drawfilledrectanglewh(45, 5, 30, 30, 'blue', 'all(empty, 11)');
    $image->drawfilledrectanglewh(85, 5, 30, 30, 'red', 'all(biseau, 11)');
    
    $image->drawfilledrectanglewh(5, 45, 30, 30, 'black', 'all(biseau2, 11)');
    $image->drawfilledrectanglewh(45, 45, 30, 30, 'blue', 'all(biseau3, 11)');
    $image->drawfilledrectanglewh(85, 45, 30, 30, 'red', 'all(biseau4, 11)');
    
    $image->drawfilledrectanglewh(5, 85, 30, 30, 'black', 'all(round, 11)');
    $image->drawfilledrectanglewh(45, 85, 30, 30, 'blue', 'all(round2, 11)');
    $image->drawfilledrectanglewh(85, 85, 30, 30, 'red', 'all(curve, 11)');
    
    $image->drawfilledrectanglewh(5, 125, 30, 30, 'black', 'all(curve2, 11)');
    $image->drawfilledrectanglewh(45, 125, 30, 30, 'blue', 'all(curve3, 11)');
    $image->drawfilledrectanglewh(85, 125, 30, 30, 'red', 'all(curve4, 11)');
    
    $image->drawfilledrectanglewh(5, 165, 30, 30, 'black', 'all(curve5, 11)');
    $image->drawfilledrectanglewh(45, 165, 30, 30, 'blue', 'all(curve6, 11)');
    $image->drawfilledrectanglewh(85, 165, 30, 30, 'red', 'all(trait, 11)');
    
    $image->drawfilledrectanglewh(5, 205, 30, 30, 'black', 'all(trait2, 11)');
    $image->drawfilledrectanglewh(45, 205, 30, 30, 'blue', 'all(trait3, 11)');
    $image->drawfilledrectanglewh(85, 205, 30, 30, 'red', 'all(round2+curve, 11)');
    
    $image->drawfilledrectanglewh(5, 245, 30, 30, 'black', 'all(curve5+curve6, 11)');
    $image->drawfilledrectanglewh(45, 245, 30, 30, 'blue', 'all(round%2+round2, 11)');
    $image->drawfilledrectanglewh(85, 245, 30, 30, 'red', 'all(trait2+trait, 11)');
    $image->format = 'png';
    $image->display();

drawimage
Draw an image.
  1. Syntax
    drawimage(& $src, $dstx, $dsty, $srcx=0, $srcy=0, $srcw=0, $srch=0, 
              $alpha=-1, $dstpos='', $srcpos='', $shapestyle='', 
              $watermark=false, $creux=true)
    
    $src        : source image
    $dstx       : destination - X value
    $dsty       : destination - Y value
    $srcx       : source - X value
    $srcy       : source - Y value
    $srcw       : source width
    $srch       : source height
    $alpha      : transparency to apply
    $dstpos     : destination position (look at copy method for examples)
    $srcpos     : source position (look at copy method for examples)
    $shapestyle : shape style (several values separated by spaces)
                  values syntax: '([%int], width[, height])'
                  corner : 'all',
    		               'tl' (top left),
    			    	   'tr' (top right),
    					   'bl' (bottom left),
    					   'br' (bottom right)
    			  shape  : 'biseau', 'biseau2', 'biseau3', 'biseau4',
    			           'round', 'round2',
    			           'curve', 'curve2', 'curve3', 'curve4', 'curve5', 'curve6',
    					   'trait', 'trait2', 'trait3',
    					   'empty', 'none'
    			  int    : hatching space (integer)
    $watermark  : whether to apply watermark effect on the image
    $creux      : whether to invert watermark effect or not
    
  2. Example.
    require(__DIR__.'/../../src/class.PHPImage.php');
    $flowers = new PHPImage('tulipes.jpg');
    $flowers->resizefit(100);
    $image = new PHPImage(120, 180);
    $image->fill(0, 0, 'white');
    $image->drawimage($flowers, 10, 10);
    $image->drawimage($flowers, 5, 90, '25%', '25%', '50%', '50%', '50%');
    $image->drawimage($flowers, 65, 90, '25%', '25%', '50%', '50%', 0, '', '', 'all(biseau, 12)');
    $image->drawimage($flowers, 5, 135, '25%', '25%', '50%', '50%', 0, '', '', 'all(round%2, 12)');
    $image->drawimage($flowers, 65, 135, '25%', '25%', '50%', '50%', '70%', '', '', 'all(curve, 12)', true);
    $flowers->destroy();
    $image->format = 'png';
    $image->display();

drawline
Draw a line.
If line color, thickness or line style are not set, this will take the last values used.
  1. Syntax
    drawline($x1, $y1, $x2, $y2, $linecolor='', $thickness=0, $linestyle='')
    
    $x1        : x point 1
    $y1        : y point 1
    $x2        : x point 2
    $y2        : y point 2
    $linecolor : line color
    $thickness : thickness
    $linestyle : line style (solid, dot, square, dash, bigdash, double, triple)
    
  2. Example.
    require(__DIR__.'/../../src/class.PHPImage.php');
    $image = new PHPImage(120, 180);
    $blue = 'blue 20%';
    $red  = 'red 20%';
    
    $image->drawline(110, 10, 10, 170, 'green 60%', 15, 'double');
    $image->drawline(10, 10, 110, 170, 'green 60%', 15, 'dot');
    
    $image->drawline(10, 10, 50, 80, $blue, 1, 'solid');
    $image->drawline(20, 10, 60, 80, $blue, 1, 'square');
    $image->drawline(30, 10, 70, 80, $blue, 1, 'dot');
    $image->drawline(40, 10, 80, 80, $blue, 1, 'dash');
    $image->drawline(50, 10, 90, 80, $blue, 1, 'bigdash');
    
    $style = array(  // '' empty string means no color at all
    
    	$blue, $blue, $blue, ''   ,
    	$blue, $blue, ''   , ''   ,
    	$blue, ''   , ''   , ''   ,
    	''   , ''   , ''   , $red ,
    	''   , ''   , $red , $red ,
    	''   , $red , $red , $red ,
    	''   , ''   , $red , $red ,
    	''   , ''   , ''   , $red ,
    	$blue, ''   , ''   , ''   ,
    	$blue, $blue, ''   , ''   ,
    );
    $image->drawline(10, 90, 110, 90, '', 4, $style);
    
    $image->drawline(10, 100, 50, 170, $red, 5, 'solid');
    $image->drawline(20, 100, 60, 170, $red, 5, 'square');
    $image->drawline(30, 100, 70, 170, $red, 5, 'dot');
    $image->drawline(40, 100, 80, 170, $red, 5, 'dash');
    $image->drawline(50, 100, 90, 170, $red, 5, 'bigdash');
    $image->drawline(60, 100, 100, 170, $red, 5, 'double');
    $image->drawline(70, 100, 110, 170, $red, 5, 'triple');
    $image->format = 'png';
    $image->display();

drawlinewh
Draw a line.
If line color, thickness or line style are not set, this will take the last values used.
  1. Syntax
    drawlinewh($x1, $y1, $w, $h, $linecolor='', $thickness=0, $linestyle='')
    
    $x1        : x point 1
    $y1        : y point 1
    $w         : width
    $h         : height
    $linecolor : line color
    $thickness : thickness
    $linestyle : line style (solid, dot, square, dash, bigdash, double, triple)
    
  2. Example.
    require(__DIR__.'/../../src/class.PHPImage.php');
    $image = new PHPImage(120, 180);
    $blue = 'blue 20%';
    $red  = 'red 20%';
    
    $image->drawlinewh(110, 10, -100, 160, 'green 60%', 15, 'double');
    $image->drawlinewh(10, 10, 100, 160, 'green 60%', 15, 'dot');
    
    $image->drawlinewh(10, 10, 40, 70, $blue, 1, 'solid');
    $image->drawlinewh(20, 10, 40, 70, $blue, 1, 'square');
    $image->drawlinewh(30, 10, 40, 70, $blue, 1, 'dot');
    $image->drawlinewh(40, 10, 40, 70, $blue, 1, 'dash');
    $image->drawlinewh(50, 10, 40, 70, $blue, 1, 'bigdash');
    
    $style = array(  // '' empty string means no color at all
    
    	$blue, $blue, $blue, ''   ,
    	$blue, $blue, ''   , ''   ,
    	$blue, ''   , ''   , ''   ,
    	''   , ''   , ''   , $red ,
    	''   , ''   , $red , $red ,
    	''   , $red , $red , $red ,
    	''   , ''   , $red , $red ,
    	''   , ''   , ''   , $red ,
    	$blue, ''   , ''   , ''   ,
    	$blue, $blue, ''   , ''   ,
    );
    $image->drawlinewh(10, 90, 100, 0, '', 4, $style);
    
    $image->drawlinewh(10, 100, 40, 70, $red, 5, 'solid');
    $image->drawlinewh(20, 100, 40, 70, $red, 5, 'square');
    $image->drawlinewh(30, 100, 40, 70, $red, 5, 'dot');
    $image->drawlinewh(40, 100, 40, 70, $red, 5, 'dash');
    $image->drawlinewh(50, 100, 40, 70, $red, 5, 'bigdash');
    $image->drawlinewh(60, 100, 40, 70, $red, 5, 'double');
    $image->drawlinewh(70, 100, 40, 70, $red, 5, 'triple');
    $image->format = 'png';
    $image->display();

drawpolygon
Draw a polygon.
  1. Syntax
    drawpolygon($values, $linecolor='', $thickness=0, $linestyle='')
    
    $values    : array of coordinates
    $linecolor : line color
    $thickness : thickness
    $linestyle : line style (solid, dot, square, dash, bigdash, double, triple)
    
  2. Example.
    require(__DIR__.'/../../src/class.PHPImage.php');
    $image = new PHPImage(120, 120);
    $form1 = array(
    	array(10, 10), array(100, 10), array(50, 50), array(100, 100),
    	array(30, 80), array(20, 50), array(40, 30),
    );
    $form2 = array(
    	array(20, 100), array(95, 40), array(15, 30), array(100, 80)
    );
    $form3 = array(
    	array(20, 105), array(30, 100), array(40, 110), array(50, 100),
    	array(60, 115), array(70, 105), array(80, 120), array(90, 110),
    	array(110, 110), array(110, 60), array(100, 70), array(95, 70), array(85, 60), 
    	array(40, 95), array(90, 105), array(40, 60), array(10, 80),
    );
    $image->drawpolygon($form1, 'blue', 4, 'dot');
    $image->drawpolygon($form2, 'red', 5, 'triple');
    $image->drawpolygon($form3, 'darkgreen', 1, 'solid');
    $image->format = 'png';
    $image->display();

drawrectangle
Draw a rectangle.
If line color, thickness or line style are not set, this will take the last values used.
  1. Syntax
    drawrectangle($x1, $y1, $x2, $y2, $linecolor='', $thickness=0, $linestyle='', $shapestyle='')
    
    $x1         : x point 1
    $y1         : y point 1
    $x2         : x point 2
    $y2         : y point 2
    $linecolor  : line color
    $thickness  : thickness
    $linestyle  : line style
    $shapestyle : shape style (several values separated by spaces)
                  values syntax: '(, width[, height])'
                  corner : 'all',
    		               'tl' (top left),
    			    	   'tr' (top right),
    					   'bl' (bottom left),
    					   'br' (bottom right)
    			  shape  : 'biseau', 'biseau2', 'biseau3', 'biseau4',
    			           'round', 'round2',
    			           'curve', 'curve2', 'curve3', 'curve4', 'curve5', 'curve6',
    					   'trait', 'trait2', 'trait3',
    					   'empty', 'none'
    
  2. Example.
    require(__DIR__.'/../../src/class.PHPImage.php');
    $image = new PHPImage(120, 180);
    $image->drawrectangle(5, 5, 115, 35, 'red 20%', 4, 'solid', 'all(round, 6)');
    $image->drawrectangle(17, 17, 103, 47, 'blue 20%', 4, 'dot');
    $image->drawrectangle(29, 29, 91, 59, 'darkgreen 20%', 4, 'double', 'all(curve, 6)');
    $image->drawrectangle(41, 41, 79, 71, 'maroon 20%', 4, 'square');
    $shape = 'tl(round, 20) tr(empty, 10, 20) bl(curve, 30, 20) br(biseau, 30)';
    $image->drawrectangle(5, 80, 115, 175, 'blue', 1, 'solid', $shape);
    $image->drawrectangle(15, 90, 105, 165, 'red', 2, 'dot', $shape);
    $image->drawrectangle(25, 100, 95, 155, 'maroon', 3, 'double', $shape);
    $shape = 'all(curve+round, 20, 10) tr(curve+round, 10, 20) bl(curve+round, 10, 20)';
    $image->drawrectangle(45, 110, 75, 140, 'black', 1, 'solid', $shape);
    $image->format = 'png';
    $image->display();
  3. Line styles.
    require(__DIR__.'/../../src/class.PHPImage.php');
    $image = new PHPImage(120, 180);
    $image->drawrectangle(5, 5, 115, 175, 'black', 3, 'solid');
    $image->drawrectangle(12, 12, 108, 168, 'blue', 3, 'dot');
    $image->drawrectangle(19, 19, 101, 161, 'red', 3, 'square');
    $image->drawrectangle(26, 26, 93, 153, 'darkgreen', 3, 'dash');
    $image->drawrectangle(33, 33, 87, 147, 'orange', 3, 'bigdash');
    $image->drawrectangle(40, 40, 80, 140, 'blue', 3, 'double');
    $image->drawrectangle(50, 50, 70, 130, 'red', 5, 'triple');
    $image->format = 'png';
    $image->display();
  4. Shape styles.
    require(__DIR__.'/../../src/class.PHPImage.php');
    $image = new PHPImage(120, 280);
    $image->drawrectangle(5, 5, 35, 35, 'black', 1, 'solid', 'all(none, 11)');
    $image->drawrectangle(45, 5, 75, 35, 'blue', 1, 'solid', 'all(empty, 11)');
    $image->drawrectangle(85, 5, 115, 35, 'red', 1, 'solid', 'all(biseau, 11)');
    
    $image->drawrectangle(5, 45, 35, 75, 'black', 1, 'solid', 'all(biseau2, 11)');
    $image->drawrectangle(45, 45, 75, 75, 'blue', 1, 'solid', 'all(biseau3, 11)');
    $image->drawrectangle(85, 45, 115, 75, 'red', 1, 'solid', 'all(biseau4, 11)');
    
    $image->drawrectangle(5, 85, 35, 115, 'black', 1, 'solid', 'all(round, 11)');
    $image->drawrectangle(45, 85, 75, 115, 'blue', 1, 'solid', 'all(round2, 11)');
    $image->drawrectangle(85, 85, 115, 115, 'red', 1, 'solid', 'all(curve, 11)');
    
    $image->drawrectangle(5, 125, 35, 155, 'black', 1, 'solid', 'all(curve2, 11)');
    $image->drawrectangle(45, 125, 75, 155, 'blue', 1, 'solid', 'all(curve3, 11)');
    $image->drawrectangle(85, 125, 115, 155, 'red', 1, 'solid', 'all(curve4, 11)');
    
    $image->drawrectangle(5, 165, 35, 195, 'black', 1, 'solid', 'all(curve5, 11)');
    $image->drawrectangle(45, 165, 75, 195, 'blue', 1, 'solid', 'all(curve6, 11)');
    $image->drawrectangle(85, 165, 115, 195, 'red', 1, 'solid', 'all(trait, 11)');
    
    $image->drawrectangle(5, 205, 35, 235, 'black', 1, 'solid', 'all(trait2, 11)');
    $image->drawrectangle(45, 205, 75, 235, 'blue', 1, 'solid', 'all(trait3, 11)');
    $image->drawrectangle(85, 205, 115, 235, 'red', 1, 'solid', 'all(round+curve, 11)');
    
    $image->drawrectangle(5, 245, 35, 275, 'black', 1, 'solid', 'all(curve4+curve5, 11)');
    $image->drawrectangle(45, 245, 75, 275, 'blue', 1, 'solid', 'all(biseau+empty, 11)');
    $image->drawrectangle(85, 245, 115, 275, 'red', 1, 'solid', 'all(trait2+trait, 11)');
    $image->format = 'png';
    $image->display();

drawrectanglewh
Draw a rectangle.
If line color, thickness or line style are not set, this will take the last values used.
  1. Syntax
    drawrectanglewh($x1, $y1, $w, $h, $linecolor='', $thickness=0, $linestyle='', $shapestyle='')
    
    $x1         : x point 1
    $y1         : y point 1
    $w          : width
    $h          : height
    $linecolor  : line color
    $thickness  : thickness
    $linestyle  : line style
    $shapestyle : shape style (several values separated by spaces)
                  values syntax: '(, width[, height])'
                  corner : 'all',
    		               'tl' (top left),
    			    	   'tr' (top right),
    					   'bl' (bottom left),
    					   'br' (bottom right)
    			  shape  : 'biseau', 'biseau2', 'biseau3', 'biseau4',
    			           'round', 'round2',
    			           'curve', 'curve2', 'curve3', 'curve4', 'curve5', 'curve6',
    					   'trait', 'trait2', 'trait3',
    					   'empty', 'none'
    
  2. Example.
    require(__DIR__.'/../../src/class.PHPImage.php');
    $image = new PHPImage(120, 180);
    
    $image->drawrectanglewh(5, 5, 110, 30, 'red 20%', 4, 'solid', 'all(round, 6)');
    $image->drawrectanglewh(17, 17, 86, 30, 'blue 20%', 4, 'dot');
    $image->drawrectanglewh(29, 29, 62, 30, 'darkgreen 20%', 4, 'double', 'all(curve, 6)');
    $image->drawrectanglewh(41, 41, 38, 30, 'maroon 20%', 4, 'square');
    $shape = 'tl(round, 20) tr(empty, 10, 20) bl(curve, 30, 20) br(biseau, 30)';
    $image->drawrectanglewh(5, 80, 110, 95, 'blue', 1, 'solid', $shape);
    $image->drawrectanglewh(15, 90, 90, 75, 'red', 2, 'dot', $shape);
    $image->drawrectanglewh(25, 100, 70, 55, 'maroon', 3, 'double', $shape);
    $shape = 'all(curve+round, 20, 10) tr(curve+round, 10, 20) bl(curve+round, 10, 20)';
    $image->drawrectanglewh(45, 110, 30, 30, 'black', 1, 'solid', $shape);
    
    $image->format = 'png';
    $image->display();
  3. Line styles.
    require(__DIR__.'/../../src/class.PHPImage.php');
    $image = new PHPImage(120, 180);
    $image->drawrectanglewh(5, 5, 110, 170, 'black', 3, 'solid');
    $image->drawrectanglewh(12, 12, 96, 156, 'blue', 3, 'dot');
    $image->drawrectanglewh(19, 19, 82, 142, 'red', 3, 'square');
    $image->drawrectanglewh(26, 26, 68, 128, 'darkgreen', 3, 'dash');
    $image->drawrectanglewh(33, 33, 54, 114, 'orange', 3, 'bigdash');
    $image->drawrectanglewh(40, 40, 40, 100, 'blue', 3, 'double');
    $image->drawrectanglewh(50, 50, 20, 80, 'red', 5, 'triple');
    $image->format = 'png';
    $image->display();
  4. Shape styles.
    require(__DIR__.'/../../src/class.PHPImage.php');
    $image = new PHPImage(120, 280);
    $image->drawrectanglewh(5, 5, 30, 30, 'black', 1, 'solid', 'all(none, 11)');
    $image->drawrectanglewh(45, 5, 30, 30, 'blue', 1, 'solid', 'all(empty, 11)');
    $image->drawrectanglewh(85, 5, 30, 30, 'red', 1, 'solid', 'all(biseau, 11)');
    
    $image->drawrectanglewh(5, 45, 30, 30, 'black', 1, 'solid', 'all(biseau2, 11)');
    $image->drawrectanglewh(45, 45, 30, 30, 'blue', 1, 'solid', 'all(biseau3, 11)');
    $image->drawrectanglewh(85, 45, 30, 30, 'red', 1, 'solid', 'all(biseau4, 11)');
    
    $image->drawrectanglewh(5, 85, 30, 30, 'black', 1, 'solid', 'all(round, 11)');
    $image->drawrectanglewh(45, 85, 30, 30, 'blue', 1, 'solid', 'all(round2, 11)');
    $image->drawrectanglewh(85, 85, 30, 30, 'red', 1, 'solid', 'all(curve, 11)');
    
    $image->drawrectanglewh(5, 125, 30, 30, 'black', 1, 'solid', 'all(curve2, 11)');
    $image->drawrectanglewh(45, 125, 30, 30, 'blue', 1, 'solid', 'all(curve3, 11)');
    $image->drawrectanglewh(85, 125, 30, 30, 'red', 1, 'solid', 'all(curve4, 11)');
    
    $image->drawrectanglewh(5, 165, 30, 30, 'black', 1, 'solid', 'all(curve5, 11)');
    $image->drawrectanglewh(45, 165, 30, 30, 'blue', 1, 'solid', 'all(curve6, 11)');
    $image->drawrectanglewh(85, 165, 30, 30, 'red', 1, 'solid', 'all(trait, 11)');
    
    $image->drawrectanglewh(5, 205, 30, 30, 'black', 1, 'solid', 'all(trait2, 11)');
    $image->drawrectanglewh(45, 205, 30, 30, 'blue', 1, 'solid', 'all(trait3, 11)');
    $image->drawrectanglewh(85, 205, 30, 30, 'red', 1, 'solid', 'all(round+curve, 11)');
    
    $image->drawrectanglewh(5, 245, 30, 30, 'black', 1, 'solid', 'all(curve4+curve5, 11)');
    $image->drawrectanglewh(45, 245, 30, 30, 'blue', 1, 'solid', 'all(biseau+empty, 11)');
    $image->drawrectanglewh(85, 245, 30, 30, 'red', 1, 'solid', 'all(trait2+trait, 11)');
    $image->format = 'png';
    $image->display();

effect
Apply an effect to the image.
  1. Edge detect.
    require(__DIR__.'/../../src/class.PHPImage.php');
    $image = new PHPImage('php.gif');
    $image->effect('edgedetect');
    $image->format = 'png';
    $image->display();
  2. Emboss.
    require(__DIR__.'/../../src/class.PHPImage.php');
    $image = new PHPImage('php.gif');
    $image->effect('emboss');
    $image->format = 'png';
    $image->display();
  3. Invert colors.
    require(__DIR__.'/../../src/class.PHPImage.php');
    $image = new PHPImage('php.gif');
    $image->effect('invert');
    $image->format = 'png';
    $image->display();
  4. Grayscale.
    require(__DIR__.'/../../src/class.PHPImage.php');
    $image = new PHPImage('php.gif');
    $image->effect('grayscale');
    $image->format = 'png';
    $image->display();
  5. Blur.
    require(__DIR__.'/../../src/class.PHPImage.php');
    $image = new PHPImage('php.gif');
    // syntax : $image->effect('blur', [number]);
    
    // number = 1 (default), 2 or 3
    
    $image->effect('blur');
    $image->format = 'png';
    $image->display();
  6. Selective Blur.
    require(__DIR__.'/../../src/class.PHPImage.php');
    $image = new PHPImage('php.gif');
    // syntax : $image->effect('selective_blur', [number]);
    
    // number = 1 (default), 2 or 3
    
    $image->effect('selective_blur');
    $image->format = 'png';
    $image->display();
  7. Sharpen.
    require(__DIR__.'/../../src/class.PHPImage.php');
    $image = new PHPImage('php.gif');
    // syntax : $image->effect('sharpen', [number]);
    
    // number = 1 (default), 2 or 3
    
    $image->effect('sharpen');
    $image->format = 'png';
    $image->display();
  8. Brightness.
    require(__DIR__.'/../../src/class.PHPImage.php');
    $image = new PHPImage('php.gif');
    // syntax : $image->effect('brightness', [value]);
    
    // value default = 10
    
    $image->effect('brightness', 50);
    $image->format = 'png';
    $image->display();
  9. Contrast.
    require(__DIR__.'/../../src/class.PHPImage.php');
    $image = new PHPImage('php.gif');
    // syntax : $image->effect('contrast', [value]);
    
    // value default = 10
    
    $image->effect('contrast', 50);
    $image->format = 'png';
    $image->display();
  10. Smooth.
    require(__DIR__.'/../../src/class.PHPImage.php');
    $image = new PHPImage('php.gif');
    // syntax : $image->effect('smooth', [value]);
    
    // value default = 1
    
    $image->effect('smooth');
    $image->format = 'png';
    $image->display();
  11. Colorize.
    require(__DIR__.'/../../src/class.PHPImage.php');
    $image = new PHPImage('php.gif');
    // syntax : $image->effect('colorize', [Red], [Green], [Blue]);
    
    // RGB default = 0
    
    $image->effect('colorize', 180, 180, 0); // yellow
    
    $image->format = 'png';
    $image->display();
  12. Watermark.
    require(__DIR__.'/../../src/class.PHPImage.php');
    $image = new PHPImage('php.gif');
    // syntax : $image->effect('watermark', [invert], [blur]);
    
    // invert default = false
    
    // blur default = false
    
    $image->effect('watermark');
    $image->format = 'png';
    $image->display();
  13. Black and white with points.
    require(__DIR__.'/../../src/class.PHPImage.php');
    $image = new PHPImage('php.gif');
    // syntax : $image->effect('points', [threshold]);
    
    // threshold default = 127
    
    $image->effect('points');
    $image->format = 'png';
    $image->display();
  14. Sepia.
    require(__DIR__.'/../../src/class.PHPImage.php');
    $image = new PHPImage('php.gif');
    $image->effect('sepia'); 
    $image->format = 'png';
    $image->display();
  15. Mosaic.
    require(__DIR__.'/../../src/class.PHPImage.php');
    $image = new PHPImage('php.gif');
    // syntax : $image->effect('mosaic', [size_x], [size_y]);
    
    // size_x default = 2
    
    // size_y default = 2
    
    $image->effect('mosaic', 4);
    $image->format = 'png';
    $image->display();
  16. Vertical flip.
    require(__DIR__.'/../../src/class.PHPImage.php');
    $image = new PHPImage('php.gif');
    $image->effect('flipv');
    $image->format = 'png';
    $image->display();
  17. Horizontal flip.
    require(__DIR__.'/../../src/class.PHPImage.php');
    $image = new PHPImage('php.gif');
    $image->effect('fliph');
    $image->format = 'png';
    $image->display();
  18. Black and white with simple threshold.
    require(__DIR__.'/../../src/class.PHPImage.php');
    $image = new PHPImage('php.gif');
    // syntax : $image->effect('threshold', [threshold]);
    
    // threshold default = 127
    
    $image->effect('threshold');
    $image->format = 'png';
    $image->display();

fill
Colorize from a point.
require(__DIR__.'/../../src/class.PHPImage.php');
$image = new PHPImage('php.gif');
$image->fill(27, 23, 'red 50%');
$image->fill(60, 23, 'green 50%');
$image->fill(82, 23, 'blue 50%');
$image->format = 'png';
$image->display();

getclone
Get a clone of the image (full object copy).
$newimage = $image->getclone();

gettextbox
Return text dimensions as 2 elements array.
  1. Syntax
    gettextbox($text, $fontsize=0, $angle=0, $linespacing='', $font='')
    
    $text        : text (multiline allowed)
    $fontsize    : font size
    $angle       : text angle
    $linespacing : line spacing
    $font        : font file name
    
  2. Example.
    $image = new PHPImage(200, 100);
    
    list($width, $height) = $image->gettextbox("Hello\nWorld", 12, 0, '', 'arial.ttf');
    
    // ... or ...
    
    
    $dims = $image->gettextbox("Hello\nWorld", 12, 0, '', 'arial.ttf');
    $width = $dims[0];
    $height = $dims[1];
    

gettextposition
Get the top left position (x, y) where to draw the text.
This method is usefull if you use an angle different from 0 and with positions different from 'top left'.
  1. Syntax
    gettextposition($cx, $cy, $text, $fontsize=12, $angle=0, 
            $position='top left', $linespacing='', $font='')
    
    $cx          : X position
    $cy          : Y position
    $text        : text (multiline allowed)
    $fontsize    : font size
    $angle       : text angle
    $position    : where is the text anchor
    $linespacing : line spacing
    $font        : font file name
    
  2. Example.
    $image = new PHPImage(200, 100);
    
    list($x, $y) = $image->gettextposition(100, 50, "Hello\nWorld", 12, 60, 'bottom center', '', 'arial.ttf');
    
    // ... or ...
    
    
    $dims = $image->gettextposition(100, 50, "Hello\nWorld", 12, 60, 'bottom center', '', 'arial.ttf');
    $x = $dims[0];
    $y = $dims[1];
    

loadfromfile
Load a file in the current image.
$image = new PHPImage();
$image->loadfromfile('php.gif');

// is equivalent to


$image = new PHPImage('php.gif');

mask
Apply a black and white mask to the image.
White is transparent.
require(__DIR__.'/../../src/class.PHPImage.php');
$image = new PHPImage('php.gif');
$mask = new PHPImage('mask.png');
$image->mask($mask);
$mask->destroy();
$image->format = 'png';
$image->display();

maskalpha
Apply a mask with transparency.
Transparency levels are copied to the image.
require(__DIR__.'/../../src/class.PHPImage.php');
$image = new PHPImage('php.gif');
$mask = new PHPImage('maskalpha.png');
$image->maskalpha($mask);
$mask->destroy();
$image->format = 'png';
$image->display();

realcopy
This is copy method which merge correctly the alpha value of colors.
With high transparencies, simple GD copy doesn't show the right color.
Be carefull, this method load your CPU.
In all case, if you don't use transparency, don't use real copy !
Use realcopy property to make copies (copy, copyresize...) use this method.
  1. Syntax
    realcopy(& $src, $dstx=0, $dsty=0, $srcx=0, $srcy=0, 
         $srcw=0, $srch=0, $alpha=-1, $dstpos='', $srcpos='')
    
    $src    : source image
    $dstx   : destination - X value
    $dsty   : destination - Y value
    $srcx   : source - X value
    $srcy   : source - Y value
    $srcw   : source width
    $srch   : source height
    $alpha  : transparency to apply
    $dstpos : destination position
    $srcpos : source position
    
  2. Real copy with a transparent yellow background
    require(__DIR__.'/../../src/class.PHPImage.php');
    $php = new PHPImage('php.gif');
    $image = new PHPImage();
    $image->bgcolor = 'yellow 80%';
    $image->create($php->width, $php->height);
    $image->realcopy($php, 0,0, 0,0, 0,0, '70%');
    $php->destroy();
    $image->format = 'png';
    $image->display();
  3. GD copy with a transparent yellow background
    Look at the difference... colors are not correctly merged !
    require(__DIR__.'/../../src/class.PHPImage.php');
    $php = new PHPImage('php.gif');
    $image = new PHPImage();
    $image->bgcolor = 'yellow 80%';
    $image->create($php->width, $php->height);
    $image->copy($php, 0,0, 0,0, 0,0, '70%');
    $php->destroy();
    $image->format = 'png';
    $image->display();

replacecolor
Replace a color by another (doesn't take care of transparency).
  1. Syntax
    replacecolor($srccolor, $dstcolor, $keeptransparency=true)
    
    $srccolor : source color
    $dstcolor : destination color
    $keeptransparency : if original transparency is kept
    
  2. We kept original transparency.
    require(__DIR__.'/../../src/class.PHPImage.php');
    $image = new PHPImage('php.gif');
    $image->replacecolor('white' , 'red');
    $image->format = 'png';
    $image->display();
  3. We don't kept original transparency.
    require(__DIR__.'/../../src/class.PHPImage.php');
    $image = new PHPImage('php.gif');
    $image->replacecolor('white' , 'red', false);
    $image->format = 'png';
    $image->display();

replacecoloralpha
Replace a color by another (take care of transparency).
  1. Syntax
    replacecoloralpha($srccolor, $dstcolor, $keeptransparency=false)
    
    $srccolor : source color
    $dstcolor : destination color
    $keeptransparency : if original transparency is kept
    
  2. We kept original transparency.
    require(__DIR__.'/../../src/class.PHPImage.php');
    $image = new PHPImage('php.gif');
    $image->replacecoloralpha('white 100%' , 'red 50%', true);
    $image->format = 'png';
    $image->display();
  3. We don't kept original transparency.
    require(__DIR__.'/../../src/class.PHPImage.php');
    $image = new PHPImage('php.gif');
    $image->replacecoloralpha('white 100%' , 'red 50%');
    $image->format = 'png';
    $image->display();

resample
Resize properly the image.
require(__DIR__.'/../../src/class.PHPImage.php');
$image = new PHPImage('php.gif');
$image->resample(75, 75);
$image->format = 'png';
$image->display();

resamplefit
Resize properly the image (keep the ratio width/height).
require(__DIR__.'/../../src/class.PHPImage.php');
$image = new PHPImage('php.gif');
$image->resamplefit(75, 75);
$image->format = 'png';
$image->display();

resize
Resize properly the image (faster than resample but less quality).
require(__DIR__.'/../../src/class.PHPImage.php');
$image = new PHPImage('php.gif');
$image->resize(75, 75);
$image->format = 'png';
$image->display();

resizefit
Resize properly the image keeping the ratio width/height (faster than resamplefit but less quality).
require(__DIR__.'/../../src/class.PHPImage.php');
$image = new PHPImage('php.gif');
$image->resizefit(75, 75);
$image->format = 'png';
$image->display();

rotate
Rotate the image.
  1. Syntax
    rotate($angle, $enlarge=true)
    
    $angle   : angle
    $enlarge : enlarge the image or keep the orginal size
    
  2. Simple rotation.
    require(__DIR__.'/../../src/class.PHPImage.php');
    $image = new PHPImage('php.gif');
    $image->resample('50%');
    $image->rotate(30);
    $image->format = 'png';
    $image->display();
  3. Rotate keeping the original size.
    require(__DIR__.'/../../src/class.PHPImage.php');
    $image = new PHPImage('php.gif');
    $image->resample('50%');
    $image->rotate(30, false);
    $image->format = 'png';
    $image->display();

savetofile
Save the image into a file.
$image->savetofile('hello.jpg', $quality); // quality between 0 and 100
// or
$image->savetofile('hello.png');
// or
$image->savetofile('hello.gif');

setalpha
Set the transparency for the whole image.
  1. Syntax
    setalpha($alpha, $forcetransparentpixels=false)
    
    $alpha : transparency
    $forcetransparentpixels : whether to change the transparent pixel transparency
    
  2. Setalpha 50%.
    require(__DIR__.'/../../src/class.PHPImage.php');
    $image = new PHPImage('php.gif');
    $image->setalpha('50%');
    $image->format = 'png';
    $image->display();
  3. Setalpha 50% with transparent pixels.
    require(__DIR__.'/../../src/class.PHPImage.php');
    $image = new PHPImage('php.gif');
    $image->setalpha('50%', true);
    $image->format = 'png';
    $image->display();

setbackgroundimage
Draw an image as background.
  1. Syntax
    setbackgroundimage(& $src, $alpha=-1)
    
    $src        : source image
    $alpha      : transparency to apply
    
  2. Example.
    require(__DIR__.'/../../src/class.PHPImage.php');
    $flowers = new PHPImage('tulipes.jpg');
    $image = new PHPImage(120, 180);
    // if you use a hight transparency and on not too big images
    
    // don't forget to set realcopy to true to have a correct transparency
    
    $image->realcopy = true;
    $image->setbackgroundimage($flowers, '70%');
    $flowers->destroy();
    $image->format = 'png';
    $image->display();

setpixel
Set the color for a defined pixel.
$image->setpixel($x, $y, $color);

setresource
This method allow to load an image in a PHPImage object.
$im = imagecreatetruecolor(200, 100);
$image = new PHPImage();
$image->setresource($im);
// ...

writetext
Write text.
  1. Syntax
    writetext($cx, $cy, $text, $fontsize=0, $angle=0, 
             $color='black', $style='left', $position='top left', 
    		 $linespacing='', $font='');
    
    $cx          : X position
    $cy          : Y position
    $text        : text (multiline allowed)
    $fontsize    : font size
    $angle       : text angle
    $color       : text color
    $style       : text style (underline, shadow ...)
    $position    : where is the text anchor
    $linespacing : line spacing
    $font        : font file name or font number (1 to 5)
    
  2. Simple text without TTF font.
    require(__DIR__.'/../../src/class.PHPImage.php');
    $image = new PHPImage(120, 120);
    // font size has no effect when no TTF font is set (here 12)
    
    $image->writetext(5, 5, "hello World !", 12, 0, 'black', '', '', '', 1);
    $image->writetext(5, 26, "hello World !", 12, 0, 'red', '', '', '', 2);
    $image->writetext(5, 49, "hello World !", 12, 0, 'blue', '', '', '', 3);
    $image->writetext(5, 72, "hello World !", 12, 0, 'darkgreen', '', '', '', 4);
    $image->writetext(5, 100, "hello World !", 12, 0, 'maroon', '', '', '', 5);
    $image->format = 'png';
    $image->display();
  3. Simple text with TTF font.
    require(__DIR__.'/../../src/class.PHPImage.php');
    $image = new PHPImage(120, 120);
    $image->fontfile = __DIR__.'/verdana.ttf';
    $image->drawfilledcircle('50%', '50%', 3, 'blue 50%');
    $image->writetext('50%', '50%', "hello\nWorld !"); 
    $image->format = 'png';
    $image->display();
  4. Same as previous but with angle=30° and red color.
    require(__DIR__.'/../../src/class.PHPImage.php');
    $image = new PHPImage(120, 120);
    $image->fontfile = __DIR__.'/verdana.ttf';
    $image->drawfilledcircle('50%', '50%', 3, 'blue 50%');
    $image->writetext('50%', '50%', "hello\nWorld !", 12, 30, 'red'); 
    $image->format = 'png';
    $image->display();
  5. Style / Alignment.
    require(__DIR__.'/../../src/class.PHPImage.php');
    $image = new PHPImage(120, 180);
    $image->fontfile = __DIR__.'/verdana.ttf';
    $image->drawfilledcircle(10, 10, 3, 'blue 50%');
    $image->drawfilledcircle(10, 65, 3, 'blue 50%');
    $image->drawfilledcircle(10, 120, 3, 'blue 50%');
    $image->writetext(10, 10, "hello\nWorld !", 12, 0, 'black', 'left'); // left
    
    $image->writetext(10, 65, "hello\nWorld !", 12, 0, 'black', 'center'); // center
    
    $image->writetext(10, 120, "hello\nWorld !", 12, 0, 'black', 'right'); // right
    
    $image->format = 'png';
    $image->display();
  6. Style / Underline.
    require(__DIR__.'/../../src/class.PHPImage.php');
    $image = new PHPImage(120, 190);
    $image->fontfile = __DIR__.'/verdana.ttf';
    $image->drawfilledcircle(10, 10, 3, 'blue 50%');
    $image->drawfilledcircle(10, 45, 3, 'blue 50%');
    $image->drawfilledcircle(10, 80, 3, 'blue 50%');
    $image->drawfilledcircle(10, 115, 3, 'blue 50%');
    $image->drawfilledcircle(10, 150, 3, 'blue 50%');
    $text = "hello\nWorld !";
    $image->writetext(10, 10, $text, 12, 0, 'black', 'underline'); // simple
    
    $image->writetext(10, 45, $text, 12, 0, 'black', 'underline(red, 20%)'); // red 50%
    
    $image->writetext(10, 80, $text, 12, 0, 'black', 'underline(3px)'); // thickness
    
    $image->writetext(10, 115, $text, 12, 0, 'black', 'underline(blue, 3px, dot)'); // dot line
    
    $image->writetext(10, 150, $text, 12, 0, 'black', 'underline(darkgreen, 3px, double)'); // double line
    
    $image->format = 'png';
    $image->display();
  7. Style / Shadow.
    require(__DIR__.'/../../src/class.PHPImage.php');
    $image = new PHPImage(120, 190);
    $image->fontfile = __DIR__.'/verdana.ttf';
    $image->fill(0, 0, 'white');
    $image->drawfilledcircle(10, 10, 3, 'blue 50%');
    $image->drawfilledcircle(10, 45, 3, 'blue 50%');
    $image->drawfilledcircle(10, 80, 3, 'blue 50%');
    $image->drawfilledcircle(10, 115, 3, 'blue 50%');
    $image->drawfilledcircle(10, 150, 3, 'blue 50%');
    $text = "hello\nWorld !";
    $image->writetext(10, 10, $text, 12, 0, 'black', 'shadow'); // simple
    
    $image->writetext(10, 45, $text, 12, 0, 'black', 'shadow(red)'); // red
    
    $image->writetext(10, 80, $text, 12, 0, 'black', 'shadow(blue, 20%, noblur)'); // blue 20% no blur
    
    $image->writetext(10, 115, $text, 12, 0, 'black', 'shadow(orange, 1x, 1y, noblur)'); // set offset
    
    $image->writetext(10, 150, $text, 12, 0, 'black', 'shadow(orange, 2x, 5y, noblur)'); // set offset
    
    $image->format = 'png';
    $image->display();
  8. Style / Misc.
    require(__DIR__.'/../../src/class.PHPImage.php');
    $image = new PHPImage(120, 190);
    $image->fontfile = __DIR__.'/verdana.ttf';
    $image->fill(0, 0, 'white');
    $image->drawfilledcircle('50%', '20%', 3, 'blue 50%');
    $image->drawfilledcircle('50%', '50%', 3, 'blue 50%');
    $image->drawfilledcircle('50%', '80%', 3, 'blue 50%');
    $text = "hello\nWorld !";
    $image->writetext('50%', '20%', $text, 12, 30, 'black', 'left underline shadow'); // simple
    
    $image->writetext('50%', '50%', $text, 12, 180, 'black', 'right underline(green) shadow(red, -2x, -2y)');
    $image->writetext('50%', '80%', $text, 12, 60, 'black', 'underline(dot) shadow(red)', '', 6); 
    $image->format = 'png';
    $image->display();
  9. Text position.
    require(__DIR__.'/../../src/class.PHPImage.php');
    $image = new PHPImage(190, 190);
    $image->fontfile = __DIR__.'/verdana.ttf';
    $image->drawfilledcircle('10%', '20%', 3, 'blue 50%');
    $image->drawfilledcircle('50%', '20%', 3, 'blue 50%');
    $image->drawfilledcircle('90%', '20%', 3, 'blue 50%');
    $image->drawfilledcircle('10%', '50%', 3, 'blue 50%');
    $image->drawfilledcircle('50%', '50%', 3, 'blue 50%');
    $image->drawfilledcircle('90%', '50%', 3, 'blue 50%');
    $image->drawfilledcircle('10%', '80%', 3, 'blue 50%');
    $image->drawfilledcircle('50%', '80%', 3, 'blue 50%');
    $image->drawfilledcircle('90%', '80%', 3, 'blue 50%');
    $text = "hello\nWorld !";
    $image->writetext('10%', '20%', $text, 10, 0, 'black', '', 'top left');
    $image->writetext('50%', '20%', $text, 10, 0, 'black', '', 'top center');
    $image->writetext('90%', '20%', $text, 10, 0, 'black', '', 'top right');
    $image->writetext('10%', '50%', $text, 10, 0, 'black', '', 'center left');
    $image->writetext('50%', '50%', $text, 10, 0, 'black', '', 'center');
    $image->writetext('90%', '50%', $text, 10, 0, 'black', '', 'center right');
    $image->writetext('10%', '80%', $text, 10, 0, 'black', '', 'bottom left');
    $image->writetext('50%', '80%', $text, 10, 0, 'black', '', 'bottom center');
    $image->writetext('90%', '80%', $text, 10, 0, 'black', '', 'bottom right');
    $image->format = 'png';
    $image->display();
  10. Easy text alignment.
    require(__DIR__.'/../../src/class.PHPImage.php');
    $image = new PHPImage(120, 120);
    $image->fontfile = __DIR__.'/verdana.ttf';
    $image->writetext('50%', '50%', "center\ntext", 10, 0, 'black', 'center', 'center center');
    $image->writetext('1%', '1%', "top\nleft", 10, 0, 'black', 'left', 'top left');
    $image->writetext('99%', '1%', "top\nright", 10, 0, 'black', 'right', 'top right');
    $image->writetext('99%', '99%', "bottom\nright", 10, 0, 'black', 'right', 'bottom right');
    $image->writetext('1%', '99%', "bottom\nleft", 10, 0, 'black', 'left', 'bottom left');
    $image->format = 'png';
    $image->display();
  11. Line Spacing.
    require(__DIR__.'/../../src/class.PHPImage.php');
    $image = new PHPImage(120, 120);
    $image->fontfile = __DIR__.'/verdana.ttf';
    $image->drawfilledcircle(10, 10, 3, 'blue 50%');
    $image->drawfilledcircle(10, 70, 3, 'blue 50%');
    $image->writetext(10, 10, "hello\nWorld !", 12, 0, 'black', '', '', -5);
    $image->writetext(10, 70, "hello\nWorld !", 12, 0, 'black', '', '', 10);
    $image->format = 'png';
    $image->display();

writetextwatermark
Write text as waterark.
  1. Syntax
    writetextwatermark($cx, $cy, $text, $fontsize=0, $angle=0, 
             $creux=true, $style='left', $position='top left', 
    		 $linespacing='', $font='', $alpha=70);
    
    $cx          : X position
    $cy          : Y position
    $text        : text (multiline allowed)
    $fontsize    : font size
    $angle       : text angle
    $creux       : whether to invert watermark or not
    $style       : text style (underline, shadow ...)
    $position    : where is the text anchor
    $linespacing : line spacing
    $font        : font file name or font number (1 to 5)
    $alpha       : transparency
    
  2. Example.
    require(__DIR__.'/../../src/class.PHPImage.php');
    $flowers = new PHPImage('tulipes.jpg');
    $image = new PHPImage(120, 120);
    $image->fontfile = __DIR__.'/verdana.ttf';
    $image->setbackgroundimage($flowers);
    $image->writetextwatermark('0%', '100%', "arnapou.net", 10, 0, false, '', 'bottom left');
    $image->writetextwatermark('100%', '100%', "arnapou.net", 10, 90, false, '', 'bottom left');
    $image->writetextwatermark('100%', '0%', "arnapou.net", 10, 180, false, '', 'bottom left');
    $image->writetextwatermark('0%', '0%', "arnapou.net", 10, -90, false, '', 'bottom left');
    $image->writetextwatermark('50%', '50%', "arnapou.net", 10, 0, true, 'center', 'center');
    $image->format = 'png';
    $image->display();