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/>.
**/
function get_default_image() {
$image = imagecreate(50, 50);
$color = imagecolorallocate($image, 250, 50, 50);
imagefill($image, 0, 0, $color);
return $image;
}
/**
* Get image data from db, cache is used
* @param $imageid
* @return array image data from db
*/
function get_image_by_imageid($imageid) {
static $images = [];
if (!isset($images[$imageid])) {
$row = DBfetch(DBselect('SELECT i.* FROM images i WHERE i.imageid='.zbx_dbstr($imageid)));
$images[$imageid] = $row;
}
return $images[$imageid];
}
/**
* Resizes the given image resource to the specified size keeping the original
* proportions of the image.
*
* @param resource $source
* @param int $thumbWidth
* @param int $thumbHeight
*
* @return resource
*/
function imageThumb($source, $thumbWidth = 0, $thumbHeight = 0) {
$srcWidth = imagesx($source);
$srcHeight = imagesy($source);
if ($srcWidth > $thumbWidth || $srcHeight > $thumbHeight) {
if ($thumbWidth == 0) {
$thumbWidth = $thumbHeight * $srcWidth / $srcHeight;
}
elseif ($thumbHeight == 0) {
$thumbHeight = $thumbWidth * $srcHeight / $srcWidth;
}
else {
$a = $thumbWidth / $thumbHeight;
$b = $srcWidth / $srcHeight;