Source
<?php
/*
** Copyright (C) 2001-2025 Zabbix SIA
**
** This program is free software: you can redistribute it and/or modify it under the terms of
** the GNU Affero General Public License as published by the Free Software Foundation, version 3.
**
** This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
** without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
** See the GNU Affero General Public License for more details.
**
** You should have received a copy of the GNU Affero General Public License along with this program.
** If not, see <https://www.gnu.org/licenses/>.
**/
/**
* Calculate new color based on bg/fg colors and transparency index
*
* @param resource $image image reference
* @param array $bgColor background color, array of RGB
* @param array $fgColor foreground color, array of RGB
* @param float $alpha transparency index in range of 0-1, 1 returns unchanged fgColor color
*
* @return int A color index.
*/
function zbx_colormix($image, $bgColor, $fgColor, $alpha) {
$r = $bgColor[0] + ($fgColor[0] - $bgColor[0]) * $alpha;
$g = $bgColor[1] + ($fgColor[1] - $bgColor[1]) * $alpha;
$b = $bgColor[2] + ($fgColor[2] - $bgColor[2]) * $alpha;
return imagecolorresolvealpha($image, (int) $r, (int) $g, (int) $b, 0);
}
/**
* Draw normal line.
* PHP imageline() function is broken because it drops fraction instead of correct rounding of X/Y coordinates.
* All calls to imageline() must be replaced by the wrapper function everywhere in the code.
*
* @param resource $image image reference
* @param int $x1 first x coordinate
* @param int $y1 first y coordinate
* @param int $x2 second x coordinate
* @param int $y2 second y coordinate
* @param int $color line color
*/
function zbx_imageline($image, $x1, $y1, $x2, $y2, $color) {
imageline($image, round($x1), round($y1), round($x2), round($y2), $color);
}
/**
* Draw antialiased line
*
* @param resource $image image reference
* @param int $x1 first x coordinate
* @param int $y1 first y coordinate
* @param int $x2 second x coordinate
* @param int $y2 second y coordinate
* @param int $color line color
* @param int $style line style, one of LINE_TYPE_NORMAL (default), LINE_TYPE_BOLD (bold line)
*/
function zbx_imagealine($image, $x1, $y1, $x2, $y2, $color, $style = LINE_TYPE_NORMAL) {
$x1 = round($x1);