Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Antialias support for line, ellipse, polygon, etc. #160

Open
7 tasks
claviska opened this issue Jan 10, 2017 · 2 comments
Open
7 tasks

Antialias support for line, ellipse, polygon, etc. #160

claviska opened this issue Jan 10, 2017 · 2 comments

Comments

@claviska
Copy link
Owner

I'd love to add antialiasing to all drawing methods. The imageantialias method states it works for lines and ellipses, but it doesn't support alpha components.

I would prefer a solution that works for all shapes, although it may not be possible without writing our own shape methods (prefer not to do). This may simply be a limitation of GD.

  • Arc
  • Ellipse
  • Line
  • Polygon
  • Rounded rectangle
  • Supports $thickness
  • Supports $alpha (transparency)
@claviska
Copy link
Owner Author

Some interesting approaches are mentioned here, particularly the zoom trick.

@claviska
Copy link
Owner Author

I experimented with the zoom trick and the line method today. The results were good, but extremely slow and memory intensive. Here's a sample for anyone who wants to play with it:

  public function line($x1, $y1, $x2, $y2, $color, $thickness = 1) {
    // Create a new image $zoom times the original's size
    $zoom = 4;
    $new = new SimpleImage();
    $new->fromNew($this->getWidth() * $zoom, $this->getHeight() * $zoom, 'transparent');
    $color = $new->allocateColor($color);

    // Set thickness
    imagesetthickness($new->image, $thickness * $zoom);
    imageline($new->image, $x1 * $zoom, $y1 * $zoom, $x2 * $zoom, $y2 * $zoom, $color);

    // Now scale it down and lay it on top of the original to produce an antialias effect
    $new->resize($this->getWidth(), $this->getHeight());
    $this->overlay($new);
    $new->__destruct();

    return $this;
  }

You can change $zoom. 1 = no zoom, 2 = 2x zoom, etc. Here's what 1 - 4 look like (download to see full size image):

zoom-trick

Given the slow speed and memory usage, I don't think the zoom trick will be a good candidate for supporting antialiasing. 😭

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant