php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #52070 imagedashedline() - dashed line sometimes is not visible
Submitted: 2010-06-13 00:28 UTC Modified: 2018-03-30 16:58 UTC
From: tgabor72 at freemail dot hu Assigned: cmb (profile)
Status: Closed Package: GD related
PHP Version: 5.3.2 OS: WinXP - IIS -fastcgi
Private report: No CVE-ID: None
View Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
If you reported this bug, you can edit this bug over here.
(description)
Block user comment
Status: Assign to:
Package:
Bug Type:
Summary:
From: tgabor72 at freemail dot hu
New email:
PHP Version: OS:

 

 [2010-06-13 00:28 UTC] tgabor72 at freemail dot hu
Description:
------------
This bug first was realized by me in php 5.3.1. imagedashedline() function is not work properly. Tipically horizontal and sharp-angled dashed lines is not visible after running this function. Could someone make a patch or fix this problem?
I know this problem has already been realized in earlier versions also, but not corrected yet. 

Thanks,

Gabor

Test script:
---------------
$im=imagecreate(1200,800);
$background_color=imagecolorallocate($im,40,40,40);
$color=imagecolorallocate($im,255,255,255);
imagedashedline($im,800,400,300,400,$color); // not visible, horizontal line
imagedashedline($im,800,400,300,800,$color); // not visible
imagedashedline($im,800,400,400,800,$color); // not visible
imagedashedline($im,800,400,500,800,$color); // visible
imagedashedline($im,800,400,600,800,$color); // visible
imagedashedline($im,800,400,700,800,$color); // visible
imagedashedline($im,800,400,800,800,$color); // visible, vertical line
header("Content-type: image/png");
imagepng($im);
imagedestroy($im);



Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2010-08-17 20:55 UTC] tgabor72 at freemail dot hu
-Status: Open +Status: Closed
 [2010-08-17 20:55 UTC] tgabor72 at freemail dot hu
You can use the imagepatternedline() function with extra features instead of imagedashedline() to give a visible dashedlines and other any kind of patterned lines on your images. The routine also manages the thickness of the line. Have fun!

// imagepatternedline() function
// Routine was developed to draw any kind of straight line with thickness. Routine uses imageline() function to draw line.
// Parameters are (similar to imageline() function):
//   $image: (resource) imagefile
//   $xstart, $ystart: (int) x,y coordinates for first point
//   $xend, $yend: (int) x,y coordinates for last point
//   $color: (int) color identifier that created with imagecolorallocate()
// extra parameters:
//   $thickness: (int) thickness of line in pixel
//   $pattern: (string) pattern of line, which repeats continuously while line is being drawed.
//   If there is '1' in the pattern that means the actual dot of line is visible,
//   '0' means dot is not visible (space between two line elements).
//   All characters regard for one pixel. Default: 1 dot wide dashed line with 4-4 dots and spaces.
// Examples for pattern:
// "1" or "" continuous line
// "10" close dotline
// "10000" dotline
// "111111110000001100000011111111" dotline for design drawing
// "111111111100000011000000110000001111111111" double dotline
// some examples for using imagepatternedline():
// imagepatternedline($image,300,300,442,442,$color,200,""); // a square with 200 length of edge and rotated 45 degrees
// imagepatternedline($image,100,200,289,200,$color,100, 
//  "11001100000011001111000011001111110000001100001100"
// ."00001111001100111100000011000000110000110011001100"
// ."11000011111100111111000011001111001111000011110000"
// ."1111001111110011000011000000001100110011"); // barcode 

function imagepatternedline($image, $xstart, $ystart, $xend, $yend, $color, $thickness=1, $pattern="11000011") {
   $pattern=(!strlen($pattern)) ? "1" : $pattern;
   $x=$xend-$xstart;
   $y=$yend-$ystart;
   $length=floor(sqrt(pow(($x),2)+pow(($y),2)));
   $fullpattern=$pattern;
   while (strlen($fullpattern)<$length) $fullpattern.=$pattern;
   if (!$length) {
      if ($fullpattern[0]) imagefilledellipse($image, $xstart, $ystart, $thickness, $thickness, $color);
      return;
   }
   $x1=$xstart;
   $y1=$ystart;
   $x2=$x1;
   $y2=$y1;
   $mx=$x/$length;
   $my=$y/$length;
   $line="";
   for($i=0;$i<$length;$i++){
      if (strlen($line)==0 or $fullpattern[$i]==$line[0]) {
         $line.=$fullpattern[$i];
      }else{
         $x2+=strlen($line)*$mx;
         $y2+=strlen($line)*$my;
         if ($line[0]) imageline($image, round($x1), round($y1), round($x2-$mx), round($y2-$my), $color);
         $k=1;
         for($j=0;$j<$thickness-1;$j++) {
            $k1=-(($k-0.5)*$my)*(floor($j*0.5)+1)*2;
            $k2= (($k-0.5)*$mx)*(floor($j*0.5)+1)*2;
            $k=1-$k;
            if ($line[0]) {
               imageline($image, round($x1)+$k1, round($y1)+$k2, round($x2-$mx)+$k1, round($y2-$my)+$k2, $color);
               if ($y) imageline($image, round($x1)+$k1+1, round($y1)+$k2, round($x2-$mx)+$k1+1, round($y2-$my)+$k2, $color);
               if ($x) imageline($image, round($x1)+$k1, round($y1)+$k2+1, round($x2-$mx)+$k1, round($y2-$my)+$k2+1, $color);
            }
         }
         $x1=$x2;
         $y1=$y2;
         $line=$fullpattern[$i];
      }
   }
   $x2+=strlen($line)*$mx;
   $y2+=strlen($line)*$my;
   if ($line[0]) imageline($image, round($x1), round($y1), round($xend), round($yend), $color);
   $k=1;
   for($j=0;$j<$thickness-1;$j++) {
      $k1=-(($k-0.5)*$my)*(floor($j*0.5)+1)*2;
      $k2= (($k-0.5)*$mx)*(floor($j*0.5)+1)*2;
      $k=1-$k;
      if ($line[0]) {
         imageline($image, round($x1)+$k1, round($y1)+$k2, round($xend)+$k1, round($yend)+$k2, $color);
         if ($y) imageline($image, round($x1)+$k1+1, round($y1)+$k2, round($xend)+$k1+1, round($yend)+$k2, $color);
         if ($x) imageline($image, round($x1)+$k1, round($y1)+$k2+1, round($xend)+$k1, round($yend)+$k2+1, $color);
      }
   }
}
 [2018-03-30 16:58 UTC] cmb@php.net
-Status: Closed +Status: Re-Opened -Assigned To: +Assigned To: cmb
 [2018-03-30 16:58 UTC] cmb@php.net
Actually, this issue has been resolved as of GD 2.0.12 (released
~2002).  PHP's bundled libgd has been synchronized with GD 2.0.12
in 2003[1], but due to a merge error, the bug has not been fixed.

[1] <http://git.php.net/?p=php-src.git;a=commit;h=61026e391c26ceeef3ebce9218c6e8d4240fcb6e>
 [2018-03-30 17:48 UTC] cmb@php.net
Automatic comment on behalf of cmbecker69@gmx.de
Revision: http://git.php.net/?p=php-src.git;a=commit;h=9c37d95627f75dc300fd0af5df6c87d6ad92e363
Log: Fix #52070: imagedashedline() - dashed line sometimes is not visible
 [2018-03-30 17:48 UTC] cmb@php.net
-Status: Re-Opened +Status: Closed
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Mon Dec 09 16:01:26 2024 UTC