Login   Register  
PHP Classes
elePHPant
Icontem

File: example.php

Recommend this page to a friend!
Stumble It! Stumble It! Bookmark in del.icio.us Bookmark in del.icio.us
  Classes of Lukas Macura  >  phpimage  >  example.php  >  Download  
File: example.php
Role: Example script
Content type: text/plain
Description: example showing more images generated with single script
Class: phpimage
Generate images output and HTML to insert in pages
Author: By
Last change: Exxample simplified by using clone()
Date: 11 years ago
Size: 2,384 bytes
 

Contents

Class file image Download
<?
error_reporting
(0);

// Example to show some image capabilities.
// More images in one script ! :)
// And you can use echo and html in your script.
// SVG output is disabled in example by default because
// you must have SVG class installed first.
// See http://www.phpclasses.org/browse.html/package/457.html
// You must replace SvgDocument in svg class package with
// file included in this bundle.

include('phpimage.inc.php');

// Let's create some png image
$png = new PhpImage("png",320,200);
// This line must be here. This is called when browser want's to load raw image data
// Please leave it here to make example working. You need only ONE instance of this function
// in page even if you have more images generated. (doesn't matter what output type)
$png->PutImageIfRequested();

// Now we demonstrate that we are still in HTML context, we can put any html tags here.
echo "<table align=center border=1><tr><td>\n";

// Allocate some colors
$white $png->ColorAllocate(255,255,255);
$red $png->ColorAllocate(255,0,0);
$blue $png->ColorAllocate(0,0,255);
$green $png->ColorAllocate(0,255,0);
$black $png->ColorAllocate(0,0,0);

// Let's make one white big box
$png->FilledRectangle(0,0,$png->sx(),$png->sy,$white);

// Filled arc..
$png->FilledArc(0,0,320,200,0,90,$green,IMG_ARC_PIE);
$png->FilledArc(320,200,150,150,180,270,$red,IMG_ARC_PIE);
$png->FilledArc(320,0,100,100,90,180,$black,IMG_ARC_NOFILL);

// Filled rectangle
for ($i=1;$i<30;$i++) {
    
$c=$png->ColorAllocate($i*7,20+($i+3),0);
    
$png->FilledRectangle($i,120+$i,110+$i,170+($i/2),$c);
}

// Line
for ($i=1;$i<30;$i++) {
    
$c=$png->ColorAllocate(0,0,255*sin(deg2rad((90/30)*$i)));
    
$png->Line(220,20,130+30*cos(deg2rad($i*(360/30))),60+30*sin(deg2rad($i*(360/30))),$png->SetThickness($c,1));
    
$png->Line(200,60,230,100,$png->SetThickness($c,31-$i));
}

// Write some text
$png->String(1,20,20,"Test text 1",$red);
$png->String(2,20,40,"Test text 2",$white);
$png->StringUp(3,0,90,"Test text 3",$blue);
$png->String(5,70,100,"PHPImage sample output (png)",$black);

echo 
$png->ImageHtmlStr();

echo 
"</td></tr>";

// And do same stuff again...
// But choose another output on same page

echo "<tr><td>";

$jpg=$png->clone("jpg");

echo 
$jpg->ImageHtmlStr();

echo 
"</td></tr>";

// And SVG stuff..

$svg=$png->clone("svg");
echo 
$svg->ImageHtmlStr();

echo 
"</td></tr>";

echo 
"</table>";
?>