How to use the gd library of php to draw a rough diagonal line with anti-aliasing

Source: Internet
Author: User
How can I use the gd library of php to draw a rough diagonal line that is anti-Sawtooth? For example, the fill map drawn by polygon is jagged. The imageantialias function is invalid ., The image antialias feature is useful when the bitmap is jagged, you can compare the effects of enabling and disabling the image. how do you use the php gd library to draw a rough diagonal line that is anti-Sawtooth?
For example, the fill map drawn by polygon is jagged. The imageantialias function is invalid.

------ Solution --------------------
It is inevitable that a dot matrix is distorted.
The image antialias anti-aliasing function works. you can compare the effect of the image antialias function when it is enabled or disabled.
If you are not satisfied with the effect of imageantialias (after all, GD is not a professional image processing package), compile your own programming solution.

------ Solution --------------------
He is using scrambling encryption. if you have time, study it.
------ Solution --------------------
It's boring. it's implemented in js.
------ Solution --------------------
JS has ready-made plug-ins that make it very beautiful... What does PHP do?
------ Solution --------------------
I will give you a code written in early years for your reference.
PHP code
  Create (func_get_arc (0), func_get_arc (1); else $ this-> create (400,300);}/*** in ($ x, $ y) image position */function pixel ($ x, $ y) {$ p = $ this-> get_view ($ x, $ y); imagesetpixel ($ this-> im, $ p ['x'], $ p ['Y'], $ this-> color); $ this-> xo = $ p ['x']; $ this-> yo = $ p ['Y'];}/*** move to ($ x, $ y) */function moveto ($ x, $ y) {$ p = $ this-> get_view ($ x, $ y); $ this-> xo = $ p ['x']; $ this-> yo = $ p ['Y'];}/*** draw a line from ($ x1, $ y1) to ($ x2, $ y2) */func Tion line ($ x1, $ y1, $ x2, $ y2) {$ p1 = $ this-> get_view ($ x1, $ y1 ); $ p2 = $ this-> get_view ($ x2, $ y2); imageline ($ this-> im, $ p1 ['x'], $ p1 ['Y'], $ p2 ['x'], $ p2 ['Y'], $ this-> color);}/*** from current location to ($ x, $ y) draw line */function lineto ($ x, $ y) {$ p = $ this-> get_view ($ x, $ y); imageline ($ this-> im, $ this-> xo, $ this-> yo, $ p ['x'], $ p ['Y'], $ this-> color ); $ this-> xo = $ p ['x']; $ this-> yo = $ p ['Y'];} /*** set the current color */function color ($ cl R) {$ r = ($ clr> 16) & 0xff; $ g = ($ clr> 8) & 0xff; $ B = ($ clr) & 0xff; $ this-> color = ImageColorAllocate ($ this-> im, $ r, $ g, $ B); $ this-> fillcolor = ImageColorAllocate ($ this-> im, $ r, $ g, $ B); $ this-> filldarkcolor = ImageColorAllocate ($ this-> im, $ r/2, $ g/2, $ B/2 ); return $ this-> color;}/*** set the current fill color */function fillcolor ($ clr) {$ r = ($ clr> 16) & 0xff; $ g = ($ clr> 8) & 0xff; $ B = ($ clr) & 0xff; $ this-> Fillcolor = ImageColorAllocate ($ this-> im, $ r, $ g, $ B); return $ this-> fillcolor ;} /*** create a GD handle and set the coordinate system */function create ($ x, $ y) {$ this-> im = imagecreatetruecolor ($ x, $ y ); imageantialias ($ this-> im, 1); imagefill ($ this-> im, 0, 0, $ this-> color (0 xffffff )); $ this-> viewx = $ X-1; $ this-> viewy =-($ y-1); $ this-> winx = $ x; $ this-> winy = $ y; $ this-> orgx = 0; $ this-> orgy = 0; // $ y; $ this-> colors = $ this-> color (0xf Fffff); settype ($ this-> ksin, "double"); settype ($ this-> kcos, "double "); $ this-> ksin = sin (deg 2rad (0); $ this-> kcos = cos (deg 2rad (0 ));} /*** coordinate ing */function get_view ($ x, $ y) {$ this-> xo = $ x * $ this-> kcos-$ y * $ this-> ksin; $ this-> yo = $ x * $ this-> ksin + $ y * $ this-> kcos; $ p ['x'] = ($ this-> xo + $ this-> orgx) * ($ this-> viewx/$ this-> winx ); $ p ['Y'] = ($ this-> yo + $ this-> orgy) * ($ this-> viewy/$ this-> winy) -$ this-> v Iewy; return $ p;}/*** set limit */function set_ext ($ x, $ y = 0) {$ this-> winx = $ x; if ($ y = 0) {$ this-> winy =-$ x * $ this-> viewy/$ this-> viewx ;} else {$ this-> winy = $ y ;}/ *** sets the rotation angle */function set_r ($ p) {$ this-> ksin = sin (deg 2rad ($ p); $ this-> kcos = cos (deg 2rad ($ p ));} /*** to construct a graph, you must reload this method in the derived class */function paint () {/*** must be reloaded by the derived class * must contain the statement $ this-> create (width, height); */die ("The paint method must be reloaded by the derived class! ");}/*** Output Image */function run () {$ this-> paint (); $ func =" Image ". $ this-> type; if (! Function_exists ($ func) {$ this-> type = "png"; $ func = "Image ". $ this-> type;} Header ("Content-type: image/{$ this-> type}"); $ func ($ this-> im ); imageDestroy ($ this-> im);}/*** circular graph data generation. the parameter $ p is the coordinate rotation angle */function get_point ($ ox, $ oy, $ w, $ h, $ start, $ end) {$ a = $ w/2; $ B = $ h/2; $ rs = array (); $ I = $ start; for ($ I = $ start; $ I <= $ end; $ I + = 5) {$ n = deg 2rad ($ I ); $ x = $ a * cos ($ n); $ y = $ B * sin ($ n); $ p = $ this-> get_view ($ ox + $ x, $ oy + $ y); $ rs [] = $ p ['x']; $ rs [] = $ p ['Y']; if ($ I = $ end) break; if ($ I + 5> $ end) $ I = $ end-5 ;} $ p = $ this-> get_view ($ ox, $ oy); $ rs [] = $ p ['x']; $ rs [] = $ p ['Y']; $ rs [] = $ rs [0]; $ rs [] = $ rs [1]; return $ rs ;} /*** bow */function chord ($ left, $ top, $ w, $ h, $ start, $ end, $ z = 0) {$ ar = $ this-> get_point ($ left, $ top, $ w, $ h, $ start, $ end, $ p); for ($ I = 0; $ I
  
   
Get_view ($ ar [$ I], $ ar [$ I + 1]); $ ar [$ I] = $ p ['x']; $ ar [$ I + 1] = $ p ['Y'];} imagefilledpolygon ($ this-> im, $ ar, count ($ ar)/2-1, $ this-> fillcolor); imagepolygon ($ this-> im, $ ar, count ($ ar)/2-1, $ this-> color );} /*** sector */function pie ($ left, $ top, $ w, $ h, $ start, $ end, $ z = 0) {$ this-> get_view ($ left, $ top + $ z); $ ar = $ this-> get_point ($ left, $ top + $ z, $ w, $ h, $ start, $ end); $ this-> get_view ($ left, $ top); $ arh = $ this-> get_point ($ left, $ top, $ w, $ h, $ start, $ end); for ($ j = 0; $ j
   
    
Filltype) imagefilledpolygon ($ this-> im, $ t, 4, $ this-> filldarkcolor); else imagepolygon ($ this-> im, $ t, 4, $ this-> color);} if ($ this-> filltype) imagefilledpolygon ($ this-> im, $ ar, count ($ ar)/2-1, $ this-> fillcolor);}/*** arc */function arc ($ left, $ top, $ w, $ h, $ start, $ end, $ z = 0) {$ ar = $ this-> get_point ($ left, $ top, $ w, $ h, $ start, $ end, $ p ); $ this-> moveto ($ ar [0], $ ar [1]); for ($ I = 2; $ I
    
     
Lineto ($ ar [$ I], $ ar [$ I + 1]) ;}} /*** reload the painting method of the base class */class myGraph extends Graph {function paint () {// $ this-> create (400,300 ); $ this-> create (200,150); $ this-> set_ext (400); $ this-> set_r (10); // rotate $ this-> filltype = false; // fill $ k = 40; // high $ a = 200; // center x $ B = 150; // center y $ c = 200; // long axis $ d = 100; // short axis $ this-> color (0x000000); $ this-> color (0xff0000); $ this-> pie ($, $ B, $ c, $ d, 0,100, $ k); $ this-> color (0x00ff00); $ this-> pie ($ a, $ B, $ c, $ d, 120,240, $ k); $ this-> color (0x0000ff); $ this-> pie ($ a + 10, $ B-10, $ c, $ d, 240,360, $ k); $ this-> color (0x8080ff); $ this-> pie (50, 80, 40, 20, 0,360, 50); $ this-> line ($ a, 0, $ a, $ B * 2); $ this-> line (0, $ B, $ a * 2, $ B) ;}}$ g = new myGraph; $ g-> run ();
    
   
  

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.