In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-02-23 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/02 Report--
This article mainly introduces the PHP Grafika how to achieve graphics drawing, has a certain reference value, interested friends can refer to, I hope you can learn a lot after reading this article, the following let Xiaobian take you to understand.
1. Draw Bezier curve
Bezier curve drawing requires two endpoints, one end and one tail, and two control points in between. Therefore, there must be at least four parameters. Add a color to a total of 5 parameters.
From right to right, we explain in turn
* (array): indicates the starting point. The * parameter in the array is x, and the second parameter is y (same as below).
The second (array): control point 1 (close to the starting point), the parameters in the array are the same as above
The third (array): control point 2 (close to the end point), the parameters in the array are the same as above
Fourth (array): end point, the parameters in the array are the same as above
Fifth: color, which can be expressed in hexadecimal, for example: # ff0000
There are two ways to draw a Bezier curve. But the steps are roughly the same. 1:, open the picture; 2, draw; 3, save or output
1) choose your own library, this method requires self-judgment
The use in the namespace also needs to be noted, two more than before
Use Grafika\ Grafika; use Grafika\ Gd\ DrawingObject\ Imagick\ DrawingObject\ CubicBezier as ImagickCubicBezier; $editor = Grafika::createEditor (); $editor- > open ($image, 'yanying-smaller.jpg'); $editorName = Grafika::detectAvailableEditor (); if (' Imagick'===$editorName) {$drawingObject = new ImagickCubicBezier (array (42,180), array (230,190), array (42,45), array (300,43),'# ff0000') } else if ('Gd'===$editorName) {$drawingObject = new GdCubicBezier (array (42,180), array (230,190), array (42,45), array (300,43),' # ff0000');} $editor- > draw ($image, $drawingObject); $editor- > save ($image,'333/yanying-CubicBezier-1.jpg')
2) you can let grafika choose the appropriate class for yourself.
This method is much simpler. This time we reset the parameters and changed the line color to black.
Use Grafika\ Grafika; $editor = Grafika::createEditor (); $editor- > open ($image,' yanying-smaller.jpg'); $drawingObject = Grafika::createDrawingObject ('CubicBezier', array (42,230), array (230,237), array (42,45), array (230,43),' # 000000'); $editor- > draw ($image, $drawingObject); $editor- > save ($image,'333/yanying-CubicBezier-1.jpg')
The effect is good, and it will be much easier to get the CAPTCHA later.
2. Draw an ellipse
Although an ellipse looks difficult, you only need to figure out a few basic parameters of an ellipse.
The Ellipse parameter is used here to draw the ellipse.
This is followed by some shape and style parameters for drawing the ellipse. We describe it from left to right.
Width of the ellipse: px is the unit
Height of the ellipse: px is the unit
Position (array): the * * values in the array are x (the leftmost distance from the ellipse to the leftmost value of the image) and the second value is y (the uppermost edge of the ellipse from the uppermost value of the graph)
Border width: unit px. If set to 0, there is no border. Default is 1px.
Oval border color: this value requires the help of the color class, rather than simply filling in a color string
Fill value of the ellipse: the color is the same as above
We create a 200 inch 100, 50 to the left, 75 above, with a border of 1, a black border, and a red ellipse.
Use Grafika\ Grafika; use Grafika\ Color; $editor = Grafika::createEditor (); $editor- > open ($image,' yanying-smaller.jpg'); $drawingObject = Grafika::createDrawingObject ('Ellipse', 200,100, array (50,75), 1, new Color (' # 000000'), new Color ('# FF0000')); $editor- > draw ($image, $drawingObject); $editor- > save ($image,'333/yanying-Ellipse.jpg')
View the result
3. Draw a straight line
Drawing a straight line is a little easier.
* the parameters are an array, indicating the starting coordinates
The second parameter is the array, which represents the end coordinates
The third parameter is the order of the vertical direction, indicating which line is on top and which line is down. (the GD library is ignored. The default is 1)
The fourth parameter is color. If left empty, it defaults to black.
Let's try to draw some lines:
Use Grafika\ Grafika; use Grafika\ Color; $editor = Grafika::createEditor (); $editor- > open ($image, 'yanying-smaller.jpg'); $editor- > draw ($image, Grafika::createDrawingObject (' Line', array (0,0), array (200,200), 1, new Color ('# FF0000')); $editor- > draw ($image, Grafika::createDrawingObject ('Line', array (0,200), array (200,0), 1, new Color (' # 00F00') $editor- > draw ($image, Grafika::createDrawingObject ('Line', array (0,0), array (200,100), 1, new Color (' # 0000FF')); $editor- > draw ($image, Grafika::createDrawingObject ('Line', array (0,100), array (200,100)); $editor- > draw ($image, Grafika::createDrawingObject (' Line', array (100,0), array (100,200)); $editor- > save ($image,'333/Line.jpg')
4. Draw polygons
We use Polygon to draw polygons, where the parameter is
* the parameters are coordinate points and are an array, in which there are three arrays, each array has two values, * values represent x, and the second value represents y
Shaped like
Array (array (0), array (50), array (0))
The second parameter is the border width, 0 is none, starting from 1, the unit is px (default is 1)
The third parameter is the border color (black by default)
The fourth parameter is the fill color (default white)
Let's try to draw some figures.
Use Grafika\ Grafika; use Grafika\ Color; $editor = Grafika::createEditor (); $editor- > open ($image, 'yanying-smaller.jpg'); $editor- > draw ($image, Grafika::createDrawingObject (' Polygon', array (array (0penol 0), array (50penny 0), array (0penny 50), 1)); $editor- > draw ($image, Grafika::createDrawingObject ('Polygon', array (array), array (0LTO), array (0LT50), 1) $editor- > draw ($image, Grafika::createDrawingObject ('Polygon', array (array (100 FF0000' 0), array (140 FF0000' 50), array (100100), array (60 FF0000' 50)), 1, null, new Color (' # FF0000')); $editor- > save ($image,'333/Polygon.jpg')
5. Quadratic Bezier curve
Also known as Bates curve or Bezier curve, is a mathematical curve applied to two-dimensional graphics applications.
It looks like this.
We can easily create it with the following code
Use Grafika\ Grafika; $editor = Grafika::createEditor (); $editor- > open ($image,' yanying-smaller.jpg'); $drawingObject = Grafika::createDrawingObject ('QuadraticBezier', array (70,250), array (20,110), array (220,60),' # FF0000'); $editor- > draw ($image, $drawingObject); $editor- > save ($image,'333/yanying-QuadraticBezier.jpg')
The parameters are as follows
* the parameters are the coordinates of the starting point, and are an array of array (x _ cadence y)
The second parameter is the coordinate of the control point, which is also an array.
The third parameter is the coordinate of the end point, which is also an array, and the array is xPowery.
* one parameter is color. Default is black.
Of course, you can also use another way to create a quadratic Besse curve.
Use Grafika\ Grafika; use Grafika\ Gd\ DrawingObject\ Imagick\ DrawingObject\ QuadraticBezier as ImagickQuadraticBezier; $editorName = Grafika::detectAvailableEditor (); $editor = Grafika::createEditor (); $editor- > open ($image, 'yanying-smaller.jpg'); if (' Imagick'===$editorName) {$drawingObject = new ImagickQuadraticBezier (array (70,250), array (20,110), array (220,60),'# FF0000') } else if ('Gd'===$editorName) {$drawingObject = new GdQuadraticBezier (array (70,250), array (20,110), array (220,60),' # FF0000');} $editor- > draw ($image, $drawingObject); $editor- > save ($image,'333/yanying-QuadraticBezier-1.jpg')
6. Create a rectangle
A rectangle is actually similar to an oval, except that there are some differences in individual parameters.
You can create a rectangle directly using the following code
Use Grafika\ Grafika; use Grafika\ Color; $editorName = Grafika::detectAvailableEditor (); $editor = Grafika::createEditor (); $editor- > open ($image, 'yanying-smaller.jpg'); $editor- > draw ($image, Grafika::createDrawingObject (' Rectangle', 85,50)); / / A 85x50 no filled rectangle with a black 1px border on location 0P 0. $editor- > draw ($image, Grafika::createDrawingObject ('Rectangle', 85,50, array (105,10), 0, null, new Color (' # FF0000'); / / A 85x50 red rectangle with no border. $editor- > draw ($image, Grafika::createDrawingObject ('Rectangle', 85,50, array (105,70), 0, null, new Color (' # 00FF00')); / / A 85x50 green rectangle with no border. $editor- > draw ($image, Grafika::createDrawingObject ('Rectangle', 85,50, array (0,60), 1,' # 00000000, null)); / / No fill rectangle $editor- > save ($image,'333/yanying-Rectangle.jpg')
The parameters in it
*: width. Px is the unit
The second is the height, px is the unit
The third is an array containing two values, x: the distance from the left side of the rectangle to the left of the picture; y: the distance between the upper side of the rectangle and the upper side of the picture. The default is array (0J0), which means it overlaps with the upper left corner.
The fourth parameter is the width of the border. The default is 1. When set to 0, there is no border.
The fifth parameter is the color of the border. The default is black. When set to null, there is no color.
The sixth parameter is the fill color, which defaults to white. When set to null, it means there is no color.
We drew several rectangles.
Thank you for reading this article carefully. I hope the article "how to achieve graphic drawing in Grafika in PHP" shared by the editor will be helpful to everyone. At the same time, I also hope that you will support and pay attention to the industry information channel. More related knowledge is waiting for you to learn!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.