PHP Classes

PHP CAD 2D: Draw vectorial graphics in an image canvas

Recommend this page to a friend!
  Info   Example   Screenshots   View files Files   Install with Composer Install with Composer   Download Download   Reputation   Support forum   Blog    
Ratings Unique User Downloads Download Rankings
Not yet rated by the usersTotal: 77 All time: 10,160 This week: 40Up
Version Licenses PHP version Categories
php-cad2d 1.0Custom (specified...5PHP 5, Graphics
Description 

Author

This package can draw vectorial graphics in an image canvas.

It can create a canvas with a given width, height, and scale factor.

The package can draw several vectorial graphics on the canvas with adjustable parameters like colors, line widths, text styles, etc...

It can render the graphics and output them to an image file in PNG format.

Currently, it can draw:

- Points

- Lines

- Rectangles

- Ellipse

- Polygons

- Text strings

- Arrows

- Grids

- Ellipses

- Dimension

- Etc...

Picture of Win Aung Cho
  Performance   Level  
Name: Win Aung Cho is available for providing paid consulting. Contact Win Aung Cho .
Classes: 11 packages by
Country: Myanmar Myanmar
Age: 61
All time rank: 24954 in Myanmar Myanmar
Week rank: 128 Up1 in Myanmar Myanmar Up
Innovation award
Innovation award
Nominee: 3x

Example

<?php
/******
 * CAD2D
 *
 * [CAD2D] class create 2 dimensional engineering drawing.
 * Entity Data are strore in the associative array.
 * Class draw the drawing on image after entity data.
 * This class is free for the educational use as long as maintain this header together with this class.
 * Author: Win Aung Cho
 * Contact winaungcho@gmail.com
 * version 1.0
 * Date: 10-02-2023
 *
 ******/
require_once ("../src/cad2d.php");

$model2d = new CAD2D();
$model2d->drawGrid(-50, -50, 300, 600, 50);
// basic line entity
$ent = array(
   
'p1' => array(
       
'x' => 0,
       
'y' => 0
   
) ,
   
'p2' => array(
       
'x' => 200,
       
'y' => 400
   
)
);
$model2d->lineWidth(2);
$model2d->setColor(BLUE);
$model2d->drawLine($ent);

// line type
$ent['p1']['y'] += 50;
$ent['p2']['y'] += 50;
$ent['pat'] = DASHDOT;
$ent['ltscale'] = 5.0;
$model2d->setColor(RED);
$model2d->drawLine($ent);

// line with offset
$ent['pat'] = null;
$ent['p1']['y'] += 50;
$ent['p2']['y'] += 50;
$ent['off1'] = 50;
$ent['off2'] = - 50;
$model2d->setColor(GREEN);
$model2d->drawLine($ent);

// line width
$model2d->setColor(BLUE);
$ent = [];
$ent['p1'] = [x => 50, y => 0];
$ent['p2'] = [x => 200, y => 350];
$t = 1;

for (
$i = 0;$i < 300;$i += 50)
{
   
$model2d->lineWidth($t);
   
$model2d->drawLine($ent);
   
$t++;
   
$ent['p1']['x'] += 50;
   
$ent['p2']['y'] -= 50;
}

$fname = "cadline.png";
imagePng($model2d->canvas, './images/'.$fname);
imagedestroy($model2d->canvas);

echo
"<img src='images/$fname?u=".time()."'/>";
?>


Details

PHP-CAD2D

CAD2D is a class to create an engineering drawing. Entity data are stored in the associative array. Class draw the drawing on image after pre-defined entity data.

PHP-CAD2D

Usage

First include the cad2d.php class in your file, and use the class as following to create drawing.

<?php
require_once ("cad2d.php");

$model2d = new CAD2D();
$model2d->setCanvas(200, 800, 1.5);
$model2d->drawGrid(-50, -50, 300, 600, 50);

$fname = "cad2dsample.png";
imagePng($model2d->canvas, './images/'.$fname);
imagedestroy($model2d->canvas);

echo "<img src='images/$fname?u=".time()."'/>";
?>

Examples

Draw Line

Line drawing example code PHP-CAD2D

Draw Polylines And Filling Hatch

Poly Line and Hatch drawing example PHP-CAD2D

Draw Ellipse And Filling Hatch

Ellipse drawing example PHP-CAD2D

Draw Dimension

Dimension drawing example PHP-CAD2D

Draw Text

Text drawing example PHP-CAD2D

Draw Rectangle And Points

Rectangle and Point drawing example PHP-CAD2D

Contact

Contact me for comercial use via mail winaungcho@gmail.com.


Screenshots (6)  
  • cad2darray.png
  • cad2ddim.png
  • cadellipse.png
  • cadlines.png
  • cadpoly.png
  • cadtext.png
  Files folder image Files (24)  
File Role Description
Files folder imageexample (6 files, 1 directory)
Files folder imageimages (8 files)
Files folder imagesrc (1 file)
Accessible without login Plain text file LICENSE Lic. License text
Accessible without login Plain text file README.md Doc. Read me

  Files folder image Files (24)  /  example  
File Role Description
Files folder imageimages (1 file)
  Accessible without login Plain text file cad2ddim.php Example Example script
  Accessible without login Plain text file cad2dellipse.php Example Example script
  Accessible without login Plain text file cad2drectpt.php Example Example script
  Accessible without login Plain text file cad2dtext.php Example Example script
  Accessible without login Plain text file cadline.php Example Example script
  Accessible without login Plain text file cadpoly.php Example Example script

  Files folder image Files (24)  /  example  /  images  
File Role Description
  Accessible without login Plain text file index.php Aux. Auxiliary script

  Files folder image Files (24)  /  images  
File Role Description
  Accessible without login Image file cad2darray.png Data Auxiliary data
  Accessible without login Image file cad2ddim.png Output Result image
  Accessible without login Image file cad2dellipse.png Output Result image
  Accessible without login Image file cad2drectpt.png Output Result image
  Accessible without login Image file cad2dtext.png Output Result image
  Accessible without login Image file cadline.png Output Result image
  Accessible without login Image file cadpoly.png Output Result image
  Accessible without login Plain text file index.php Aux. Auxiliary script

  Files folder image Files (24)  /  src  
File Role Description
  Plain text file cad2d.php Class Class source

The PHP Classes site has supported package installation using the Composer tool since 2013, as you may verify by reading this instructions page.
Install with Composer Install with Composer
 Version Control Unique User Downloads Download Rankings  
 75%
Total:77
This week:0
All time:10,160
This week:40Up