Intervention / Intervention/image

drawLine() ignores transparent colors with GD <= 2.1.0

Open
#1,349 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
PHP
Stars
14.4k
Forks
1.5k
Avg merge
17h 51m
Merged PRs (30d)
11

Description

Describe the bug

The drawLine() function ignores a transparent color and draws the line completely opaque. #ffffff44 for example is drawn as #ffffffff.

The erroneous output was observed with GD version bundled (2.1.0 compatible), which is now about 8 years old and no longer supported. However, it still seems to be unfortunately present in many installations. For example, a recent official PHP 8.3 Docker image still contains this old version.

With a setup with the same version the line width is also ignored. See #1304

There were no problems with current GD versions (e.g. 2.3.3).

Code Example

$image = $manager
    ->create(500, 500)
    ->fill('ff5500')
    ->drawLine(function (LineFactory $line) {
        $line->color('fff4'); // transparency!
        $line->from(100, 100);
        $line->to(400, 100);
    });

Expected behavior

Function should draw line (half) transparent according to given color.

Environment

  • PHP Version: 8.1
  • OS: Debian
  • Intervention Image Version: 3.6.3
  • GD or Imagick: GD bundled (2.1.0 compatible)

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by reproducing the drawLine() example with GD bundled 2.1.0-compatible, then trace the drawLine() entry point and its GD-specific handling. Done means transparent colors render with the requested alpha on the affected GD version while current GD behavior remains intact; the report does not name files or tests.

Written by the indexing model from the issue text.

Assessment

Tech stack
php
Domain
computer-graphics
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.