pkg.graphics.php

Package contenente le classi per la manipolazione grafica:

  1. Dimension
  2. Point
  3. Color
  4. Image
  5. Font
  6. Graphics

Può essere uno strumento molto utile per chi, abituato a programmare grafica in Java, vuole portare la facilità di programmazione ad oggetti in un contesto non Object Oriented.

Le classi sono molto semplici da utilizzare. Ecco un rapido excursus tra le varie classi implementate per capire come usarle.

Dimension

$dim = new Dimension(100, 100);
 
printf("%d, %d",$dim->getWidth(), $dim->getHeight());

Point

$p = new Point(100, 100);
 
printf("%d, %d",$p->getX(), $p->getY());

Color

$c = new Color(255, 20, 30);
 
printf("[R: %d, G: %d, B: %d]",$c->getRed(), $c->getGreen(), $c->getBlue());

Font

//Utilizza font di sistema implementati in PHP
$f = new Font(3);
 
//Utilizza font TTF secondo il percorso indicato
$f = new Font("/font/MyFont.ttf", 30);
 
printf("Font: %s, Size: %d", $f->getFont(), $f->getSize());

Image

$im = new Image("/image/Image.jpg");
 
print $im->getImageName();
print $im->getWidth();
print $im->getHeight();

Graphics

$g = new Graphics(100, 100);
 
//Stampa dell'oggetto Graphics creato
var_dump($g);
 
$g->drawLine(0, 0, $g->getWidth(), $g->getHeight());
 
$g->fillRect(0, 0, 10, 10);
 
$g->setColor(new Color(255, 0, 0));
 
$g->fillRect(15, 15, 10, 10);
 
$g->fillOval(30, 30, 10, 10);
 
$g->drawImage(new Image("Immagine.jpg", 30, 10, 10, 10);
 
$g->drawString("Stringa", 0, 40);
 
$g->setFont(new Font("Font.ttf", 50));
 
$g->drawString("Stringa", 0, 40);
 
$g->renderImage("ImmagineRenderizzata.png");