Source
<?php
/*
** Zabbix
** Copyright (C) 2001-2023 Zabbix SIA
**
** This program is free software; you can redistribute it and/or modify
** it under the terms of the GNU General Public License as published by
** the Free Software Foundation; either version 2 of the License, or
** (at your option) any later version.
**
** 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 General Public License for more details.
**
** You should have received a copy of the GNU General Public License
** along with this program; if not, write to the Free Software
** Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
**/
/**
* 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