GD Library



( ZN >= 3.0.0 )

This library was created using PHP's gd library to make it more fluid and easy to use.

 

 

# Preliminary Information


There is no need to use the imageallocate () method to use colors in the GD Library .

For the use of color R | G | B | A form ie 0-255 | 0-255 | 0-255 | 0-127 specified format. The letter A at the end expresses the alpha value.

Custom color names can also be used. white, purple, pink ...

Parameters such as x, y, width, height, color which are usually used in drawings are used under the $ settings array parameter . Thus , it was possible to reduce the number of parameters and to avoid mixing of the parameter sequences.

 

 

# Methods


this canvas ( $ width , $ height , $ rgb , $ real , $ p1 )
Mixed generate ( String $ type , String $ save )
this line ( Array $ settings )
this rectangle ( Array $ settings )
this arc ( Array $ settings )
this ellipse ( Array $ settings )
this polygon ( Array $ settings )
this char ( String $ char , Array $ settings )
this text ( String $ text , Array $ settings )
this fill ( Array $ settings )
this filter ( String $ filter , Int $ arg1 = 0 , Int $ arg2 = 0 , Int $ arg3 = 0 , Int $ arg4 = 0 )
this flip ( String $ type )
this alphablending ( Boolean $ blendMode = NULL )
this savealph to ( Boolean $ saver = true )
this smooth ( Bool $ mode = true )
this convolution ( Array $ matrix , Float $ div = 0 , Float $ offset = 0 )
this interlace ( Int $ interlace = 0 )
this mix ( $ source , Array $ settings )
this mixGray ( $ source , Array $ settings )
this copy ( $ source , Array $ settings )
this resample ( $ source , Array $ settings )
this resize ( $ source , Array $ settings )
this crop ( Array $ settings )
this autoCrop ( String $ mode = 'default' , Float $ threshold = .5, Int $ color = -1)
this quality ( Int $ quality )
this screenshot ()
this rotate ( Float $ angle , String $ spaceColor = '0 | 0 | 0' , Int $ ignoreTransparent = 0 )
this scale ( Int $ width , Int $ height = -1, String $ mode = 'bilinear_fixed' )
this interpolation ( String $ method = 'bilinear_fixed' )
this pixel ( Array $ settings )
this style ( Array $ style )
this thickness ( Int $ thickness = 1 )
this tile ( $ tile )
this windowDisplay ( Int $ window , Int $ clientArea = 0 )
this layerEffect ( String $ effect = 'normal' )
this toWbmp ( String $ fileName , Int $ threshold = NULL )
this save ( String $ file )
this type ( String $ type )
this output ( Bool $ output )
Int closest ( String $ rgb )
Int resolve ( String $ rgb )
Int index ( String $ rgb )
Int pixelIndex ( Int $ x , Int $ y )
Int closestHwb ( String $ rgb )
Int total ()
String thumb ( String $ filePath , Array $ settings )
Bool jpegToWbmp ( String $ jpegFile , String $ wbmpFile , Array $ settings = NULL )
Bool pngToWbmp ( String $ pngFile , String $ wbmpFile , Array $ settings = NULL )
Int fontHeight ( Int $ height )
Int fontWidth ( Int $ width )
Int loadFont ( String $ file )
Mixed copyPalette ( $ source )
Int canvaswidth ()
Int canvasheight ()
Int types ()
Mixed createFrom ( String $ type , String $ source , Array $ settings )
Object size ( String $ fileName )
String extension ( String $ type = 'jpeg' , Bool $ dote = true )
String mime ( String $ type = 'jpeg' )
String result ()
Array info ()

 

 

# Canvas ( ZN> = 3.0.0 )


It creates a canvas for drawing. There are 2 types of parameter arrays.

Parameters - Canvas

The parameter sequence used to create an empty background is as follows.

Int $ width Canvas width.
Int $ height The height of the canvas.
String $ color = 'transparent' Canvas background color.
Bool $ real = false True color value.
return this
Parameters - Image

Canvas is used as picture.

String $ file Image file name or path.
return this  
Use of
GD::canvas(200, 400, 'white')->generate('png');
Canvas Picture

To use the picture on the canvas, you can give the path to the first parameter.

GD::canvas('thumb/example-image.png')->generate('png');

 

 

# Generate ( ZN >= 3.0.0 )


It is the final method used to complete the image formation after the applied operations .

Parameters
String $ Type Specifies what kind of content the image to be created will have.
Options jpeg , gif , png , gd , gd2 , wbmp , webp , xbm , xpm
String $ saver If the created image is requested to be saved, path and name information will be written to this parameter. If this parameter is not used, the output is reflected on the screen.
return Mixed
Use of
GD::canvas(200, 400, 'white')->generate('png', 'thumb/example-image');
Generated file: thumb / example-image.png

 

 

# Line ( ZN >= 3.0.0 )


Used to draw lines on the canvas.

Parameters
Array $ settings Used to configure the drawing settings.
Keys Int x1 Start point in the horizontal plane.
Int y1 Start point in vertical plane.
Int x2 End point in the horizontal plane.
Int y2 End point in vertical plane.
String color The color of my drawing.
Options red , solomon , blue  ... '255 | 0 | 75' , '0 | 10 | 127' ...
String type It's the kind of drawing.
Options dashed , solid
return this
Use of
GD::canvas(400, 400, 'transparent')
  ->x1(100)->y1(100)->x2(200)->y2(200)->color('red')->line()
  ->x1(100)->y1(100)->x2(0)->y2(0)->color('blue')->line()
  ->generate('png');

 

 

# Rectangle ( ZN >= 3.0.0 )


Used to draw a rectangle on the canvas.

Parameters
Array $ settings Used to configure the drawing settings.
Keys Int x Start point in the horizontal plane.
Int y Start point in vertical plane.
Int width Width value in pixels.
Int height Height value in pixels.
String color The color of my drawing.
Options red , solomon , blue  ... '255 | 0 | 75' , '0 | 10 | 127' ...
String type It's the kind of drawing.
Options fille
return this
Use of
GD::canvas(200, 400, 'white')
  ->x(0)->y(0)->width(100)->height(100)->color('255|0|255')->rectangle()
  ->x(100)->y(100)->width(100)->height(100)->color('blue')->type('fill')->rectangle()
  ->generate('png');

 

 

# Arc ( ZN >= 3.0.0 )


Used to draw an arc to a canvas.

Parameters
Array $ settings Used to configure the drawing settings.
Keys Int x Start point in the horizontal plane.
Int y Start point in vertical plane.
Int width Width value in pixels.
Int height Height value in pixels.
Int start The angle is the starting value.
Int end Angle ending value.
String color The color of my drawing.
Options red , solomon , blue  ... '255 | 0 | 75' , '0 | 10 | 127' ...
String type It's the kind of drawing.
Options pie , chord , edged , nofill
return this
Use of
GD::canvas(200, 200, 'white')
  ->x(0)->y(0)->width(100)->height(100)->color('pink')->start(0)->end(90)->type('pie')->arc()
  ->generate('jpeg');

 

 

# Ellipse  ( ZN >= 3.0.0 )


Used to draw ellipses.

Parameters
Array $ settings Used to configure the drawing settings.
Keys Int x Start point in the horizontal plane.
Int y Start point in vertical plane.
Int width Width value in pixels.
Int height Height value in pixels.
String color The color of my drawing.
Options red , solomon , blue  ... '255 | 0 | 75' , '0 | 10 | 127' ...
String type It's the kind of drawing.
Options fille
return this
Use of
GD::canvas(200, 200, 'white')
  ->x(100)->y(100)->width(100)->height(100)->color('red')->type('fill')->ellipse()
  ->generate('jpeg');

 

 

# Polygon  ( ZN >= 3.0.0 )


Used to draw polygons.

Parameters
Array $ settings Used to configure the drawing settings.
Keys Array points Point coordinates.
Int pointCount = points / 2 Corner number. automatically calculated based on the points key.
String color The color of my drawing.
Options red , solomon , blue  ... '255 | 0 | 75' , '0 | 10 | 127' ...
String type It's the kind of drawing.
Options nofill
return this
Use of
GD::color('red')->canvas(300, 300)
  ->color('white')->points([0, 0, 100, 200, 300, 200])->polygon()
  ->generate('jpeg');

 

 

# Char  ( ZN >= 3.0.0 )


Used to draw characters.

Parameters
Array $ settings Used to configure the drawing settings.
Keys Int x Start point in the horizontal plane.
Int y Start point in vertical plane.
Int font  Font type. The value to specify is 1 , 2 , 3 , 4 , 5 for built-in typefaces with Latin2 coded
String color The color of my drawing.
Options red , solomon , blue  ... '255 | 0 | 75' , '0 | 10 | 127' ...
String type It's the kind of drawing.
Options vertical , horizontal
return this
Use of
GD::color('white')->canvas(300, 300)
  ->color('red')->font(5)->x(40)->y(40)->char('H')
  ->generate('jpeg');

 

 

# Text  ( ZN >= 3.0.0 )


Used to draw text.

Parameters
Array $ settings Used to configure the drawing settings.
Keys Int x Start point in the horizontal plane.
Int y Start point in vertical plane.
Int font  Font type. The value to specify is 1 , 2 , 3 , 4 , 5 for built-in typefaces with Latin2 coded
String color The color of my drawing.
Options red , solomon , blue  ... '255 | 0 | 75' , '0 | 10 | 127' ...
String type It's the kind of drawing.
Options vertical , horizontal
return this
Use of
GD::color('white')->canvas(300, 300)
  ->color('red')->font(5)->x(40)->y(100)->type('vertical')->text('Hello!')
  ->generate('jpeg');

 

 

# Fill  ( ZN >= 3.0.0 )


It is used for painting the picture.

Parameters
Array $ settings Used to configure the drawing settings.
Keys Int x Start point in the horizontal plane.
Int y Start point in vertical plane.
String borderColor Frame color.
String color The color of my drawing.
Options red , solomon , blue  ... '255 | 0 | 75' , '0 | 10 | 127' ...
String type It's the kind of drawing.
Options fille
return this
Use of
GD::color('white')->canvas(300, 300)
  ->x(100)->y(100)->arc()
  ->x(200)->y(200)->arc()
  ->color('purple')->x(100)->y(100)->fill()
  ->color('blue')->x(200)->y(200)->fill()
  ->generate('jpeg');

 

 

# Filter  ( ZN >= 3.0.0 )


The image is used to filter.

Parameters
String $ FilterName Filter name.
Int $ Args ... Filter parameters.
return this
Filters
Parametric Array Explanation
filter ( 'negate' ) All colors in the image are converted to the opposite color.
filter ( 'greyscale' ) Makes the picture grayscale.
filter ( 'brightness' , Int $ level ) It changes the brightness of the Resin.
filter ( 'constrast' , Int $ level ) Reseminate changes the level of opposition.
filter ( 'colorize' , Int $ red , Int $ green , Int $ blue , Int $ alpha ) It transforms the image into the desired color gradation. Colors 0 to 255 The last $ to alpha parameter takes a value from 0 to 127 .
filter ( 'edgedetect' ) Edge detection is used to emphasize the resident edges.
filter ( 'emboss' ) The image embossing is applied.
filter ( 'gaussianBlur' ) Blurs the image using the Gaussian method.
filter ( 'selectiveBlur' ) Blurs the image using the Gaussian method.
filter ( 'meanRemoval' ) Scribble implements deletion to create a draft effect.
filter ( 'smooth' , Int $ level ) Resmin softens hard lines. 
filter ( 'pixelate' , Int $ size , Bool $ effect = false ) It can not use the mosaic effect of advanced.
Use of
GD::canvas(RESOURCES_DIR . 'wallpaper.jpg')
  ->filter('colorize', 80, 50, 60)
  ->filter('brightness', 80)
  ->generate();

 

 

# Flip  ( ZN >= 3.0.0 )


Used to rotate the image by parameter.

Parameters
String $ type = 'both' Direction.
Options horizontal , vertical , both
return this
Use of
GD::canvas(RESOURCES_DIR . 'wallpaper.jpg')
  ->filter('colorize', 80, 50, 60)
  ->flip()
  ->generate();

 

 

# AlphaBlending  ( ZN >= 3.0.0 )


It is used to activate the collation mode.

Parameters
Bool $ mode = false Is the collation mode active?
return this
Use of
GD::canvas(RESOURCES_DIR . 'wallpaper.jpg')
  ->alphaBlending(true)
  ->generate();

 

 

# SaveAlpha  ( ZN >= 3.0.0 )


Used to specify whether to save alpha channel information while saving PNG images.

Parameters
Bool $ save = false Are you recording alpha channel information?
return this
Use of
GD::canvas(RESOURCES_DIR . 'wallpaper.jpg')
  ->saveAlpha(true)
  ->generate();

 

 

# Smooth  ( ZN >= 3.0.0 )


Used to apply softness to edges.

Parameters
Bool $ mode = false Are you recording alpha channel information?
return this
Use of
GD::canvas(RESOURCES_DIR . 'wallpaper.jpg')
  ->smooth(true)
  ->generate();

 

 

# Convolution  ( ZN >= 3.0.0 )


The image is used to apply a 3x3 matrix.

Parameters
Array $ matrix 3x3 matrix.
float $ div = 0 Conversion result coefficient used for normalization.
float $ offset = 0 Location.
return this
Use of
GD::canvas(RESOURCES_DIR . 'wallpaper.jpg')
  ->convolution([[2, 0, 0], [0, -1, 0], [0, 0, -1]], 1, 127)
  ->generate();

 

 

# Interlace  ( ZN >= 3.0.0 )


Used to toggle the toggle.

Parameters
Int $ interlace = 0 If it is different from zero, the picture will be transparent, otherwise the transition bit will be closed.
return this
Use of
GD::canvas(RESOURCES_DIR . 'wallpaper.jpg')
  ->interlace(1)
  ->generate('png');

 

 

# Mix  ( ZN >= 3.0.0 )


2 is used to mix the picture in a certain place. 

Optional Methods
this target ( Int $ x , Int $ y ) The destination is the image specified by the canvas () method.
Int $ x The canvas will begin to blend with the image in the horizontal plane.
Int $ y The canvas will begin to blend in the vertical plane with a few pixels in the image.
this source ( Int $ x , Int $ y ) The image is determined by the source mix () method.
Int $ x The starting point in the horizontal plane of the section to be taken from the source image.
Int $ y The starting point in the vertical plane of the section to be taken from the source image.
this width ( Int $ width ) The width of the section to be taken from the source image.
this height ( Int $ height ) Height of the section taken from the source image.
this percent ( Int $ percent ) Mixing ratio. The value is between 0 and 100 , and the two images are mixed according to this transparency ratio. No additional processing is done for the 0 value. For 100 , when alpha transparency is applied to real color images,  the approach in the copy () method is applied to palette images  .
Use of
GD::canvas(RESOURCES_DIR . 'wallpaper.jpg')
   ->target(50, 50)
   ->source(300, 450)
   ->width(200)
   ->height(200)
   ->percent(50)
   ->mix(RESOURCES_DIR . 'wallpaper2.jpg')
   ->generate('png');

 

 

# MixGray  ( ZN >= 3.0.0 )


2 is used to mix the picture in a certain proportion in gray tones.

Optional Methods
this target ( Int $ x , Int $ y ) The destination is the image specified by the canvas () method.
Int $ x The canvas will begin to blend with the image in the horizontal plane.
Int $ y The canvas will begin to blend in the vertical plane with a few pixels in the image.
this source ( Int $ x , Int $ y ) The image is determined by the source mix () method.
Int $ x The starting point in the horizontal plane of the section to be taken from the source image.
Int $ y The starting point in the vertical plane of the section to be taken from the source image.
this width ( Int $ width ) The width of the section to be taken from the source image.
this height ( Int $ height ) Height of the section taken from the source image.
this percent ( Int $ percent ) Mixing ratio. The value is between 0 and 100 , and the two images are mixed according to this transparency ratio. No additional processing is done for the 0 value. For 100 , when alpha transparency is applied to real color images,  the approach in the copy () method is applied to palette images  .
Use of
GD::canvas(RESOURCES_DIR . 'wallpaper.jpg')
   ->target(50, 50)
   ->source(300, 450)
   ->width(200)
   ->height(200)
   ->percent(50)
   ->mixGray(RESOURCES_DIR . 'wallpaper2.jpg')
   ->generate('png');

 

 

# Copy  ( ZN> = 3.0.0 )


Resmin is used to copy another part of the image to a specific location.

Optional Methods
this target ( Int $ x , Int $ y ) The destination is the image specified by the canvas () method.
Int $ x The canvas will begin to blend with the image in the horizontal plane.
Int $ y The canvas will begin to blend in the vertical plane with a few pixels in the image.
this source ( Int $ x , Int $ y ) The image is determined by the source mix () method.
Int $ x The starting point in the horizontal plane of the section to be taken from the source image.
Int $ y The starting point in the vertical plane of the section to be taken from the source image.
this width ( Int $ width ) The width of the section to be taken from the source image.
this height ( Int $ height ) Height of the section taken from the source image.
Use of
GD::canvas(RESOURCES_DIR . 'wallpaper.jpg')
   ->target(50, 50)
   ->source(300, 450)
   ->width(200)
   ->height(200)
   ->copy(RESOURCES_DIR . 'wallpaper2.jpg')
   ->generate('png');

 

 

# Resample  / Resize ( ZN >= 3.0.0 )


Used to copy and resize a resample of a resample.

Optional Methods
this target ( Int $ x , Int $ y ) The destination is the image specified by the canvas () method.
Int $ x The canvas will begin to blend with the image in the horizontal plane.
Int $ y The canvas will begin to blend in the vertical plane with a few pixels in the image.
this source ( Int $ x , Int $ y ) The image is determined by the source mix () method.
Int $ x The starting point in the horizontal plane of the section to be taken from the source image.
Int $ y The starting point in the vertical plane of the section to be taken from the source image.
this sourceWidth ( Int $ width ) The width of the section to be taken from the source image.
this sourceHeight ( Int $ height ) Height of the section taken from the source image.
this targetWidth ( Int $ width ) The width of the section taken from the canvas picture.
this targetHeight ( Int $ height ) The height of the section from the canvas picture.
Use of
GD::canvas(RESOURCES_DIR . 'wallpaper.jpg')
  ->target(50, 50)
  ->source(300, 450)
  ->targetWidth(300)
  ->targetHeight(300)
  ->sourceWidth(10)
  ->sourceHeight(10)
  ->resample(RESOURCES_DIR . 'wallpaper2.jpg')
  ->generate('png');

 

 

# Crop  ( ZN >= 3.0.0 )


It is used to retrieve a piece of resize.

Optional Methods
this x ( Int $ x ) The cross section will begin to be picked up in the horizontal plane.
this y ( Int $ y ) The cross section will start in the vertical plane with a few pixels.
this width ( Int $ width ) The width of the section taken from the canvas.
this height ( Int $ height ) The height of the section from the canvas.
Use of
GD::canvas(RESOURCES_DIR . 'wallpaper.jpg')
  ->x(100)->y(100)->width(100)->height(300)->crop()
  ->generate('png');

 

 

# AutoCrop  ( ZN> = 3.0.0 )


It is used to automatically crop a video using one of the available modes.

Parameters
String $ mode = 'default' Mod.
Options Default, black, white, transparent, sides
float $ threshold = .5 It can only be used with threshold mode. 5: Specifies the tolerance in percentage to be used when comparing the image color and the color to be trimmed.
Int $ color = -1 It can only be used with threshold mode. Specifies the percentage tolerance to be used when comparing image color and color to be cropped.
return this
Use of
GD::canvas(RESOURCES_DIR . 'wallpaper.jpg')
  ->autoCrop('threshold', .5, 255)
  ->generate('png');

 

 

# Quality  ( ZN >= 3.0.0 )


Used to increase or decrease resident quality.

Parameters
Int $ quality Quality. PNG 0-10 for files , 0-100 for others .
return this
Use of
GD::canvas(RESOURCES_DIR . 'wallpaper.jpg')
  ->quality(5)
  ->generate();

 

 

# Screenshot  ( ZN> = 3.0.0 )


It is used to capture an image of the entire screen.

Parameters
void
return this
Use of
GD::screenshot()->generate('png');

 

 

# ToWbmp  ( ZN >= 3.0.0 )


Outputs a WBMP image to a file or to a browser.

Parameters
String $ fileName = NULL The path to the file to save the Resmin. If not given, the raw image stream is sent directly to the scanner. 
Int $ threshold = NULL Threshold value; It is a value between 0-255 .
return this
Use of
GD::canvas(RESOURCES_DIR . 'wallpaper.jpg')
  ->toWbmp('example')
  ->generate('png');