Rubblewebs

THESE CODES ARE PROVIDED FOR AN EXAMPLE OF HOW TO USE IMAGEMAGICK WITH PHP. CARE SHOULD BE TAKEN WHEN ACCEPTING USER INPUT.

I TAKE NO RESPONSABILTY FOR ANY PROBLEMS THAT MAY OCCURE WHEN USING ANY OF THIS CODE.

IT IS UP TO YOU TO SECURE THE CODE AND VALIDATE USER INPUT.

Imagick Draw functions page: 1

Annotation

Draws text on the image.

Annotation example
$im = new Imagick();
$im->newImage( 200, 150, 'NavajoWhite' );
$draw = new ImagickDraw();
$draw->setFillColor( 'Black' );
$draw->setFont ( 'handsean.ttf' );
$draw->setFontSize ( 30 );
$draw->setGravity (Imagick::GRAVITY_CENTER);
$draw->annotation( 0, 0, 'Rubblewebs');
$im->drawImage( $draw );
$im->writeImage('annotation.jpg'); 
$im->destroy();

Arc

Draws an arc falling within a specified bounding rectangle on the image.

Arc example
$im = new Imagick();
$im->newImage( 200, 150, 'NavajoWhite' );
$draw = new ImagickDraw();
$draw->setFillColor('none');
$draw->setStrokeColor( 'Black' );
$draw->setStrokeWidth(1); 
$draw->arc( 66,50, 200,150, 0,135 );
$im->drawImage( $draw );
$im->writeImage('draw_arc.jpg'); 
$im->destroy();

Bezier

Draws a bezier curve

Bezier example
$im = new Imagick();
$im->newImage( 200, 150, 'NavajoWhite' );
$points = array(
array( 'x' => 1, 'y' => 150 ),
array( 'x' => 0, 'y' => 0 ),  
array( 'x' => 199, 'y' => 150 ), 
array( 'x' => 199, 'y' => 0 ));
$draw = new ImagickDraw();
$draw->setFillColor('none');
$draw->setStrokeColor( 'Black' );
$draw->setStrokeWidth(1); 
$draw->bezier( $points );
$im->drawImage( $draw );
$im->writeImage('bezier.jpg'); 
$im->destroy();

Circle

Drawers a circle

Circle example
Another Circle example
$im = new Imagick();
$im->newImage( 200, 150, 'NavajoWhite' );
$draw = new ImagickDraw();
$draw->setStrokeColor( 'Black' );
$draw->setStrokeWidth(1); 
$draw->circle( 100, 75, 100, 10 );
$im->drawImage( $draw );
$im->writeImage('draw_circle_filled.jpg'); 
$im->destroy();


$im = new Imagick();
$im->newImage( 200, 150, 'NavajoWhite' );
$draw = new ImagickDraw();
$draw->setFillColor('none');
$draw->setStrokeColor( 'Black' );
$draw->setStrokeWidth(1); 
$draw->circle( 100, 75, 100, 10 );
$im->drawImage( $draw );
$im->writeImage('draw_circle_empty.jpg'); 
$im->destroy();

Color

Draws color on image using the current fill color, starting at specified position, and using specified paint method.

Color example
$im = new Imagick();
$im->newImage( 200, 150, 'NavajoWhite' );
$draw = new ImagickDraw();
$draw->setFillColor('Blue');
$draw->color( 50, 50, 1 );
$im->drawImage( $draw );
$im->writeImage('color.jpg'); 
$im->destroy();

( 1 - imagick::PAINT_POINT
2 - imagick::PAINT_REPLACE
3 - imagick::PAINT_FLOODFILL
4 - imagick::PAINT_FILLTOBORDER
5 - imagick::PAINT_RESET
Not working as expected )

Line

Draws a line on the image using the current stroke color, stroke opacity, and stroke width.

Line example
$im = new Imagick();
$im->newImage( 200, 150, 'NavajoWhite' );
$draw = new ImagickDraw();
$draw->setFillColor('none');
$draw->setStrokeColor( 'Black' );
$draw->setStrokeWidth(1); 
$draw->line( 10,140, 190,10 );
$im->drawImage( $draw );
$im->writeImage('draw_line.jpg'); 
$im->destroy();

Path close

Adds a path element to the current path

Not working

/*
$im = new Imagick();
$im->newImage( 200, 150, 'NavajoWhite' );
$draw = new ImagickDraw();
$points = array(
array( 'x' => 1, 'y' => 150 ),
array( 'x' => 10, 'y' => 0 ),  
array( 'x' => 189, 'y' => 150 ), 
array( 'x' => 199, 'y' => 0 ));
$draw->setFillColor('none');
$draw->setStrokeColor( 'Black' );
$draw->setStrokeWidth(1); 
$draw->polyline( $points );
$draw->pathClose ();
$im->drawImage( $draw );
$im->writeImage('pathClose.jpg'); 
$im->destroy();
*/

Point

Draws a point using the current stroke color and stroke thickness at the specified coordinates.

Point example
$im = new Imagick();
$im->newImage( 200, 150, 'NavajoWhite' );
$draw = new ImagickDraw();
$draw->setFillColor('Black');
$draw->point( 100, 75 );
$im->drawImage( $draw );
$im->writeImage('draw_point.jpg'); 
$im->destroy();

Polygon

Draws a polygon using the current stroke, stroke width, and fill color or texture, using the specified array of coordinates.

Polygon example
$im = new Imagick();
$im->newImage( 200, 150, 'NavajoWhite' );
$draw = new ImagickDraw();
$points = array(
array( 'x' => 100, 'y' => 15 ),
array( 'x' => 150, 'y' => 65 ),  
array( 'x' => 120, 'y' => 120 ), 
array( 'x' => 80, 'y' => 120 ));
$draw->setFillColor('none');
$draw->setStrokeColor( 'Black' );
$draw->setStrokeWidth(2); 
$draw->polygon( $points );
$im->drawImage( $draw );
$im->writeImage('draw_polygon.jpg'); 
$im->destroy();

Polyline

Draws a polyline using the current stroke, stroke width, and fill color or texture, using the specified array of coordinates.

Polyline example
$im = new Imagick();
$im->newImage( 200, 150, 'NavajoWhite' );
$draw = new ImagickDraw();
$points = array(
array( 'x' => 1, 'y' => 150 ),
array( 'x' => 10, 'y' => 0 ),  
array( 'x' => 189, 'y' => 150 ), 
array( 'x' => 199, 'y' => 0 ));
$draw->setFillColor('none');
$draw->setStrokeColor( 'Black' );
$draw->setStrokeWidth(1); 
$draw->polyline( $points );
$im->drawImage( $draw );
$im->writeImage('draw_polyline.jpg'); 
$im->destroy();

Rectangle

Draws a rectangle given two coordinates and using the current stroke, stroke width, and fill settings.

Rectangle example
$im = new Imagick();
$im->newImage( 200, 150, 'NavajoWhite' );
$draw = new ImagickDraw();
$draw->setFillColor('none');
$draw->setStrokeColor( 'Black' );
$draw->setStrokeWidth(1); 
$draw->rectangle( 20, 20, 180, 130 );
$im->drawImage( $draw );
$im->writeImage('rectangle.jpg'); 
$im->destroy();

Rotate

Applies the specified rotation to the current coordinate space.

Rotate example
$im = new Imagick();
$im->newImage( 200, 150, 'NavajoWhite' );
$draw = new ImagickDraw();
$draw->setFillColor('none');
$draw->setStrokeColor( 'Black' );
$draw->setStrokeWidth(1); 
$draw->roundRectangle( 20, 20, 180, 130,10, 10 );
$draw->rotate(10);
$draw->roundRectangle( 20, 20, 180, 130,10, 10 );
$draw->rotate(10);
$draw->roundRectangle( 20, 20, 180, 130,10, 10 );
$im->drawImage( $draw );
$im->writeImage('rotate.jpg'); 
$im->destroy();

Round rectangle

Draws a rounded rectangle

Round rectangle example
$im = new Imagick();
$im->newImage( 200, 150, 'NavajoWhite' );
$draw = new ImagickDraw();
$draw->setFillColor('none');
$draw->setStrokeColor( 'Black' );
$draw->setStrokeWidth(1); 
$draw->roundRectangle( 20, 20, 180, 130,10, 10 );
$im->drawImage( $draw );
$im->writeImage('roundRectangle.jpg'); 
$im->destroy();

Scale

Adjusts the scaling factor to apply in the horizontal and vertical directions to the current coordinate space.

Scale example
$im = new Imagick();
$im->newImage( 200, 150, 'NavajoWhite' );
$draw = new ImagickDraw();
$draw->setFillColor('none');
$draw->setStrokeColor( 'Black' );
$draw->setStrokeWidth(1); 
$draw->rectangle( 20, 20, 180, 130 );
$draw->scale( 0.5, 0.5 );
$draw->rectangle( 20, 20, 180, 130 );
$im->drawImage( $draw );
$im->writeImage('scale.jpg'); 
$im->destroy();