/** * 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 array new color */ 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, $r, $g, $b, 0); }
/** * Creates blank image. * @param int * @param int * @param array * @return self */ public static function fromBlank($width, $height, $color = NULL) { if (!extension_loaded('gd')) { throw new Exception('PHP extension GD is not loaded.'); } $width = (int) $width; $height = (int) $height; if ($width < 1 || $height < 1) { throw new InvalidArgumentException('Image width and height must be greater than zero.'); } $image = imagecreatetruecolor($width, $height); if (is_array($color)) { $color += ['alpha' => 0]; $color = imagecolorresolvealpha($image, $color['red'], $color['green'], $color['blue'], $color['alpha']); imagealphablending($image, FALSE); imagefilledrectangle($image, 0, 0, $width - 1, $height - 1, $color); imagealphablending($image, TRUE); } return new static($image); }
/** * Возвращает новый экземпляр GDImage * @param string $source Путь к исходному файлу. NULL - создание пустого изображения * @param Size $s Размер изображения. NULL - использовать размеры исходного файла * @param int $resizeMode Режим изменения размера. Используется, если $s не совпадает с размерами исходного изображения * @throws GDException */ function __construct($source = NULL, Size $s = NULL, $resizeMode = self::RESIZE_FIT) { $s !== NULL or $s = new Size(100, 100); if (!empty($source)) { $this->source = (string) $source; if (!($sizes = @getimagesize($source))) { throw new GDException('Файл не является допустимым форматом изображения.'); } list($type, $subtype) = explode('/', $sizes['mime']); if ($type != 'image') { throw new GDException('Файл не является допустимым форматом изображения.'); } switch ($subtype) { case 'gif': $this->handle = @imagecreatefromgif($source); break; case 'jpeg': $this->handle = @imagecreatefromjpeg($source); break; case 'png': $this->handle = @imagecreatefrompng($source); break; default: throw new GDException('Файл не является допустимым форматом изображения.'); } if ($this->handle === FALSE) { $this->handle = NULL; throw new GDException('Невозможно инициализировать GD поток'); } $this->format = (string) $subtype; if ($s !== NULL) { $this->size($s, $resizeMode); } } else { if (($this->handle = @imagecreatetruecolor($s->width, $s->height)) === FALSE) { $this->handle = NULL; throw new GDException('Невозможно инициализировать GD поток'); } imagefill($this->handle, 0, 0, imagecolorresolvealpha($this->handle, 0, 0, 0, 127)); } }
protected function GetDarkColorIndex($color) { list($r, $g, $b, $a) = $color; $r = max(0, $r - 0x30); $g = max(0, $g - 0x30); $b = max(0, $b - 0x30); return imagecolorresolvealpha($this->img, $r, $g, $b, $a); }
function Allocate($aColor) { list($r, $g, $b) = $this->color($aColor); if ($GLOBALS['gd2'] == true) { return imagecolorresolvealpha($this->img, $r, $g, $b, 0); } else { $index = imagecolorexact($this->img, $r, $g, $b); if ($index == -1) { $index = imagecolorallocate($this->img, $r, $g, $b); if (USE_APPROX_COLORS && $index == -1) { $index = imagecolorresolve($this->img, $r, $g, $b); } } return $index; } }
/** * Call to undefined method. * * @param string method name * @param array arguments * @return mixed * @throws Nette\MemberAccessException */ public function __call($name, $args) { $function = 'image' . $name; if (!function_exists($function)) { return parent::__call($name, $args); } foreach ($args as $key => $value) { if ($value instanceof self) { $args[$key] = $value->getImageResource(); } elseif (is_array($value) && isset($value['red'])) { // rgb $args[$key] = imagecolorallocatealpha($this->image, $value['red'], $value['green'], $value['blue'], $value['alpha']) ?: imagecolorresolvealpha($this->image, $value['red'], $value['green'], $value['blue'], $value['alpha']); } } array_unshift($args, $this->image); $res = $function(...$args); return is_resource($res) && get_resource_type($res) === 'gd' ? $this->setImageResource($res) : $res; }
function Allocate($aColor, $aAlpha = 0.0) { list($r, $g, $b, $a) = $this->color($aColor); if ($a > 0) { $aAlpha = $a; } if ($aAlpha < 0 || $aAlpha > 1) { JpGraphError::RaiseL(25080); } return imagecolorresolvealpha($this->img, $r, $g, $b, round($aAlpha * 127)); }
<?php header('content-type:image/jpeg'); //在白色背景上绘制一个椭圆 $image = imagecreatetruecolor(150, 150); $white = imagecolorallocate($image, 255, 255, 255); imagealphablending($image, false); imagefilledrectangle($image, 0, 0, 150, 150, $white); $red = imagecolorresolvealpha($image, 255, 50, 0, 50); imagefilledellipse($image, 75, 75, 80, 63, $red); imagejpeg($image); imagedestroy($image);
print_r(imagecolorsforindex($im, $c)); // with alpha $im = imagecreatetruecolor(5, 5); $c = imagecolorclosestalpha($im, 255, 0, 255, 100); printf("%X\n", $c); imagedestroy($im); $im = imagecreate(5, 5); $c = imagecolorclosestalpha($im, 255, 0, 255, 100); print_r(imagecolorsforindex($im, $c)); imagedestroy($im); $im = imagecreate(5, 5); imagecolorallocatealpha($im, 255, 0, 255, 1); $c = imagecolorclosestalpha($im, 255, 0, 255, 1); print_r(imagecolorsforindex($im, $c)); imagedestroy($im); $im = imagecreate(5, 5); for ($i = 0; $i < 255; $i++) { imagecolorresolvealpha($im, $i, 0, 0, 1); } $c = imagecolorclosestalpha($im, 255, 0, 0, 1); print_r(imagecolorsforindex($im, $c)); $im = imagecreate(5, 5); for ($i = 0; $i < 256; $i++) { if ($i == 246) { imagecolorallocatealpha($im, $i, 10, 10, 1); } else { imagecolorallocatealpha($im, $i, 0, 0, 100); } } $c = imagecolorclosestalpha($im, 255, 10, 10, 1); print_r(imagecolorsforindex($im, $c));
function Allocate($aImg, $aColor, $aAlpha = 0.0) { $res = $this->Color($aColor); if ($res === false) { return false; } list($r, $g, $b, $a) = $res; if ($a > 0) { $aAlpha = $a; } if ($aAlpha < 0 || $aAlpha > 1) { return false; } return imagecolorresolvealpha($aImg, $r, $g, $b, round($aAlpha * 127)); }
public function resolve($rgb = '') { if (!!is_string($rgb)) { Error::set(lang('Error', 'stringParameter', '1.(rgb)')); return false; } $rgb = explode('|', $rgb); $red = isset($rgb[0]) ? $rgb[0] : 0; $green = isset($rgb[1]) ? $rgb[1] : 0; $blue = isset($rgb[2]) ? $rgb[2] : 0; $alpha = isset($rgb[3]) ? $rgb[3] : 0; return imagecolorresolvealpha($this->canvas, $red, $green, $blue, $alpha); }
/** * Apply tools to image. * * This function scan for mask color and closes colors position, grab color * at found the position on sample image, then set the pixel color at the same * position on destination image. * * @return bool|PEAR_Error TRUE on success or PEAR_Error on failure. * @access private * @see Image_Tools_Mask::_getNearestColors() */ function render() { if (!Image_Tools::isGDImageResource($this->_maskImage)) { return PEAR::raiseError('Invalid image resource Image_Tools_Mask::$_maskImage'); } if (!Image_Tools::isGDImageResource($this->_sampleImage)) { return PEAR::raiseError('Invalid image resource Image_Tools_Mask::$_sampleImage'); } if (!Image_Tools::isGDImageResource($this->resultImage)) { return PEAR::raiseError('Invalid image resource Image_Tools_Mask::$_resultImage'); } $maskWidth = imagesx($this->_maskImage); $maskHeight = imagesy($this->_maskImage); $sampleWidth = imagesx($this->_sampleImage); $sampleHeight = imagesy($this->_sampleImage); if ($this->options['antialias']) { $closesColors = $this->_getNearestColors(); } else { $closesColors = array($this->options['maskColor']); } imagealphablending($this->resultImage, true); // scan for mask color or closes colors position for ($x = 0; $x < $maskWidth; $x++) { for ($y = 0; $y < $maskHeight; $y++) { if ($x >= $sampleWidth || $y >= $sampleHeight) { continue; } // grab color at x, y and convert to hex color format $index = imagecolorat($this->_maskImage, $x, $y); $maskRGBA = imagecolorsforindex($this->_maskImage, $index); $maskColor = Image_Color::rgb2hex(array_values($maskRGBA)); // check color in closes colors collection if (in_array($maskColor, $closesColors)) { // grab color at x, y from sample image $index = imagecolorat($this->_sampleImage, $x, $y); $sampleRGBA = imagecolorsforindex($this->_sampleImage, $index); // allocate color on destination image $color = imagecolorresolvealpha($this->resultImage, $sampleRGBA['red'], $sampleRGBA['green'], $sampleRGBA['blue'], $sampleRGBA['alpha']); // set a pixel color at destination image imagesetpixel($this->resultImage, $x, $y, $color); } } } return true; }
} else { imagecolorresolve($im, $i, 0, 0); } } $c = imagecolorresolve($im, 255, 10, 10); print_r(imagecolorsforindex($im, $c)); // with alpha $im = imagecreatetruecolor(5, 5); $c = imagecolorresolvealpha($im, 255, 0, 255, 100); printf("%X\n", $c); imagedestroy($im); $im = imagecreate(5, 5); $c = imagecolorresolvealpha($im, 255, 0, 255, 100); print_r(imagecolorsforindex($im, $c)); imagedestroy($im); $im = imagecreate(5, 5); for ($i = 0; $i < 255; $i++) { imagecolorresolvealpha($im, $i, 0, 0, 1); } $c = imagecolorresolvealpha($im, 255, 0, 0, 1); print_r(imagecolorsforindex($im, $c)); $im = imagecreate(5, 5); for ($i = 0; $i < 256; $i++) { if ($i == 246) { imagecolorresolvealpha($im, $i, 10, 10, 1); } else { imagecolorresolvealpha($im, $i, 0, 0, 100); } } $c = imagecolorresolvealpha($im, 255, 10, 10, 0); print_r(imagecolorsforindex($im, $c));
function Allocate($aColor, $aAlpha = 0.0) { list($r, $g, $b, $a) = $this->color($aColor); // If alpha is specified in the color string then this // takes precedence over the second argument if ($a > 0) { $aAlpha = $a; } if ($aAlpha < 0 || $aAlpha > 1) { JpGraphError::RaiseL(25080); //('Alpha parameter for color must be between 0.0 and 1.0'); } return imagecolorresolvealpha($this->img, $r, $g, $b, round($aAlpha * 127)); }
function generate() { $regioncache = KB_CACHEDIR . '/img/map/' . KB_SITE . '_' . $this->regionid_ . '_' . $this->imgwidth_ . '.png'; $is_cached = 0; //INIT $title_caption = $this->regname_; if (file_exists($regioncache)) { $cfgttl = '6'; $ttyl_sec = $cfgttl * 3600; $ttl = filemtime($regioncache) + $ttyl_sec; if ($ttl <= time()) { $is_cached = 0; unlink($regioncache); unlink($regioncache . ".txt"); } else { $img = imagecreatefrompng($regioncache); $is_cached = 1; } } if ($is_cached == 0) { $sql = 'SELECT sys.sys_x, sys.sys_y, sys.sys_z, sys.sys_sec, sys.sys_id, sys.sys_name, sys.sys_id, sjp.sjp_to, con.con_id, con.con_name, reg.reg_id, reg.reg_name, reg.reg_x, reg.reg_z FROM kb3_systems sys LEFT JOIN kb3_system_jumps sjp ON sys.sys_id = sjp.sjp_from JOIN kb3_constellations con ON con.con_id = sys.sys_con_id JOIN kb3_regions reg ON reg.reg_id = con.con_reg_id'; if ($this->mode_ == "sys") { $sql .= " and reg.reg_id = '" . $this->regionid_ . "'"; } else { $sql .= " and reg.reg_id = " . $this->regionid2_; } $qry = new DBQuery(); $qry->execute($sql) or die($qry->getErrorMsg()); if (!$img) { $img = imagecreatetruecolor($this->imgwidth_, $this->imgheight_); } $white = imagecolorallocate($img, 255, 255, 255); $red = imagecolorallocate($img, 255, 0, 0); if (config::get('map_act_cl_bg')) { $bcolor = explode(",", config::get('map_act_cl_bg')); mapview::setbgcolor($bcolor[0], $bcolor[1], $bcolor[2]); } $bgcolor = imagecolorallocate($img, $this->bgcolor_[0], $this->bgcolor_[1], $this->bgcolor_[2]); imagefilledrectangle($img, 0, 0, $this->imgwidth_, $this->imgheight_, $bgcolor); $color = $white; $fov = 0; //INIT $i = 0; $minx = 0; $minz = 0; $maxx = 0; $maxz = 0; $mini = 0; $maxi = 0; $pi = 0; $sc = 0; $systems = array(); while ($row = $qry->getRow()) { $i = $row['sys_id']; $systems[] = $i; if ($i < $mini || $mini == 0) { $mini = $i; } if ($i > $maxi || $maxi == 0) { $maxi = $i; } $x = $row['sys_x'] * $this->ly_; $z = $row['sys_z'] * $this->ly_; if ($x < $minx || $minx == 0) { $minx = $x; } if ($x > $maxx || $maxx == 0) { $maxx = $x; } if ($z < $minz || $minz == 0) { $minz = $z; } if ($z > $maxz || $maxz == 0) { $maxz = $z; } $sys[$i][0] = $x; $sys[$i][1] = $z; if ($i == $pi || $pi == 0) { $sys[$i][2][$sc] = $row['sjp_to']; $sys[$i][3] = $sc++; } else { $sc = 0; } $sys[$i][4] = $row['sys_id']; $sys[$i][5] = $row['sys_name']; $sys[$i][6] = $row['sys_sec']; $sys[$i][7] = $row['con_id']; $sys[$i][8] = $row['con_name']; $sys[$i][9] = $row['reg_id']; $sys[$i][10] = $row['reg_name']; $pi = $i; } $dx = abs($maxx - $minx); $dz = abs($maxz - $minz); $xscale = 1 / ($dx / ($this->imgwidth_ - $this->offset_ * 2)); $yscale = 1 / ($dz / ($this->imgheight_ - $this->offset_ * 2)); // draw lines if ($this->showlines_) { if (config::get('map_act_cl_line')) { $lcolor = explode(",", config::get('map_act_cl_line')); mapview::setlinecolor($lcolor[0], $lcolor[1], $lcolor[2]); } foreach ($systems as $n) { $px = $this->offset_ + ($sys[$n][0] - $minx) * $xscale; $py = $this->offset_ + ($sys[$n][1] - $minz) * $yscale; $line_col = imagecolorallocate($img, $this->linecolor_[0], $this->linecolor_[1], $this->linecolor_[2]); for ($m = 0; $m <= $sys[$n][3]; $m++) { $sys_to = $sys[$n][2][$m]; if ($sys[$sys_to][4] != "") { $px_to = $this->offset_ + ($sys[$sys_to][0] - $minx) * $xscale; $py_to = $this->offset_ + ($sys[$sys_to][1] - $minz) * $yscale; imageline($img, $px, $py, $px_to, $py_to, $line_col); } } $n++; } } //---------------------------------------------- // draw systems //---------------------------------------------- foreach ($systems as $n) { if (config::get('map_act_cl_normal')) { $scolor = explode(",", config::get('map_act_cl_normal')); mapview::setnormalcolor($scolor[0], $scolor[1], $scolor[2]); } $px = round($this->offset_ + ($sys[$n][0] - $minx) * $xscale); $py = round($this->offset_ + ($sys[$n][1] - $minz) * $yscale); $color = imagecolorallocate($img, $this->normalcolor_[0], $this->normalcolor_[1], $this->normalcolor_[2]); imagefilledellipseaa($img, $px, $py, 4, 4, $color); //gm this is the white system dot, shrunkg it down from 6x6 size $n++; } imagepng($img, $regioncache); $fp = fopen($regioncache . ".txt", "w"); // writting offset data into file if ($fp) { // This step is needed cause when the image is cached only 1 system is queried from the DB // therefor it is impossible to calculcate the offset again. fwrite($fp, $maxx . "\n" . $minx . "\n" . $maxz . "\n" . $minz); } fclose($fp); } //--------------------------------------------------------------------------------------- //System Highlight starts here //--------------------------------------------------------------------------------------- if ($this->mode_ == "sys") { $sql = "SELECT sys.sys_x, sys.sys_y, sys.sys_z, sys.sys_sec, sys.sys_id, sys.sys_name, sys.sys_id\n\t\t\t\t\tFROM kb3_systems sys\n\t\t\t\t\tWHERE sys.sys_id = '" . $this->systemid_ . "'"; $qry = new DBQuery(); $qry->execute($sql) or die($qry->getErrorMsg()); $fov = 0; //INIT $row = $qry->getRow(); $x = $row['sys_x'] * $this->ly_; $z = $row['sys_z'] * $this->ly_; $sys[0] = $x; $sys[1] = $z; $sys[4] = $row['sys_id']; $sys[5] = $row['sys_name']; $sys[6] = $row['sys_sec']; $fp = fopen($regioncache . ".txt", "r"); // getting offset data from file if ($fp == FALSE) { echo "failt to open {$regioncache}"; exit; } $maxx = fgets($fp); $minx = fgets($fp); $maxz = fgets($fp); $minz = fgets($fp); fclose($fp); $dx = abs($maxx - $minx); $dz = abs($maxz - $minz); $xscale = 1 / ($dx / ($this->imgwidth_ - $this->offset_ * 2)); $yscale = 1 / ($dz / ($this->imgheight_ - $this->offset_ * 2)); $px = round($this->offset_ + ($sys[0] - $minx) * $xscale); $py = round($this->offset_ + ($sys[1] - $minz) * $yscale); if (config::get('map_act_cl_hl2')) { $hscolor = explode(",", config::get('map_act_cl_hl2')); $color = imagecolorallocate($img, $hscolor[0], $hscolor[1], $hscolor[2]); } else { $color = imagecolorallocate($img, '255', '0', '0'); } $tlen = 5 * strlen($sys[5]); if ($px + $tlen > $this->imgwidth_ - 20) { $sx = $px - $tlen; } else { $sx = $px + 5; } if ($py + 5 > $this->imgheight_ - 20) { $sy = $py - 5; } else { $sy = $py + 5; } imagestring($img, 1, $sx, $sy, $sys[5], $color); imagefilledellipseaa($img, $px, $py, 6, 6, $color); } //--------------------------------------------------------------------------------------- // Activity starts here //--------------------------------------------------------------------------------------- if ($this->mode_ == "activity") { $kills = 0; //INIT $overall_kill = 0; $color = imagecolorallocate($img, $this->normalcolor_[0], $this->normalcolor_[1], $this->normalcolor_[2]); $paint_name = config::get('map_act_shownames'); $sql2 = "SELECT sys.sys_name, sys.sys_x, sys.sys_y, sys.sys_z, sys.sys_sec, sys.sys_id, count( DISTINCT kll.kll_id ) AS kills\n\t\t\t\tFROM kb3_systems sys, kb3_kills kll, kb3_inv_detail inv, kb3_constellations con, kb3_regions reg\n\t\t\t\tWHERE kll.kll_system_id = sys.sys_id\n\t\t\t\tAND inv.ind_kll_id = kll.kll_id"; if (count(config::get('cfg_allianceid'))) { $orargs[] = 'inv.ind_all_id IN (' . implode(",", config::get('cfg_allianceid')) . ") "; } if (count(config::get('cfg_corpid'))) { $orargs[] = 'inv.ind_crp_id IN (' . implode(",", config::get('cfg_corpid')) . ") "; } if (count(config::get('cfg_pilotid'))) { $orargs[] = 'inv.ind_plt_id IN (' . implode(",", config::get('cfg_pilotid')) . ") "; } $sql2 .= " AND (" . implode(" OR ", $orargs) . ")"; if (isset($this->week_)) { $sql2 .= " and date_format( kll.kll_timestamp, \"%u\" ) = " . $this->week_; } if (isset($this->month_)) { $sql2 .= " and date_format( kll.kll_timestamp, \"%m\" ) = " . $this->month_; } $sql2 .= " AND date_format( kll.kll_timestamp, \"%Y\" ) = " . $this->year_ . "\n\t\t\t\t\tAND con.con_id = sys.sys_con_id\n\t\t\t\t\tAND reg.reg_id = con.con_reg_id\n\t\t\t\t\tAND reg.reg_id =" . $this->regionid2_ . "\n\t\t\t\t\tGROUP BY sys.sys_name\n\t\t\t\t\tORDER BY kills desc"; $qry2 = new DBQuery(); $qry2->execute($sql2) or die($qry2->getErrorMsg()); while ($row2 = $qry2->getRow()) { $kills = $row2['kills']; $overall_kill = $overall_kill + $kills; //OFFSET CALCULATION $x = $row2['sys_x'] * $this->ly_; $z = $row2['sys_z'] * $this->ly_; $sys[0] = $x; $sys[1] = $z; $sys[4] = $row2['sys_id']; $sys[5] = $row2['sys_name']; $sys[6] = $row2['sys_sec']; $fp = fopen($regioncache . ".txt", "r"); // getting offset data from file $maxx = fgets($fp); $minx = fgets($fp); $maxz = fgets($fp); $minz = fgets($fp); fclose($fp); $dx = abs($maxx - $minx); $dz = abs($maxz - $minz); $xscale = 1 / ($dx / ($this->imgwidth_ - $this->offset_ * 2)); $yscale = 1 / ($dz / ($this->imgheight_ - $this->offset_ * 2)); $px = round($this->offset_ + ($sys[0] - $minx) * $xscale); $py = round($this->offset_ + ($sys[1] - $minz) * $yscale); if ($kills == 1) { // If there is only one kill we use normal highlight color $ratio = 1; if (config::get('map_act_cl_hl')) { $hscolor = explode(",", config::get('map_act_cl_hl')); $color = imagecolorallocate($img, $hscolor[0], $hscolor[1], $hscolor[2]); } else { $color = imagecolorallocate($img, '255', '209', '57'); } } else { //more then one kill... $ratio = $kills + 5; // ...then we add a bit to the ratio if (config::get('map_act_cl_hl2')) { // Set the color to Highlight 2 and the sphere color with alpha $hscolor = explode(",", config::get('map_act_cl_hl2')); $color = imagecolorallocate($img, $hscolor[0], $hscolor[1], $hscolor[2]); $color4 = imagecolorresolvealpha($img, $hscolor[0], $hscolor[1], $hscolor[2], '117'); } else { $color = imagecolorallocate($img, '255', '0', '0'); $color4 = imagecolorresolvealpha($img, 255, 0, 0, 117); } } if ($ratio > 100) { //now we limit the max-size of the sphere so it doesnt grow to big $ratio = 100; } imagefilledellipse($img, $px, $py, $ratio, $ratio, $color4); //paint the sphere -- can not use AA function cause it doesnt work with alpha imagefilledellipseaa($img, $px, $py, 6, 6, $color); // use AA function to paint the system dot if ($ratio > 10) { // extend the sphere $ratio2 = $ratio - 10; imagefilledellipse($img, $px, $py, $ratio2, $ratio2, $color4); } if ($ratio > 20) { // add another inner layer to the sphere, if it gets big enough $ratio3 = $ratio - 20; imagefilledellipse($img, $px, $py, $ratio3, $ratio3, $color4); } if ($paint_name == 1) { $tlen = 5 * strlen($sys[5]); if ($px + $tlen > $this->imgwidth_ - 20) { $sx = $px - $tlen; } else { $sx = $px + 5; } if ($py + 5 > $this->imgheight_ - 20) { $sy = $py - 5; } else { $sy = $py + 5; } imagestring($img, 1, $sx, $sy, $sys[5], $color); } } } //--------------------------------------------------------------------------------------- // Ship / Faction starts here //--------------------------------------------------------------------------------------- if ($this->mode_ == "ship" || $this->mode_ == "faction") { $kills = 0; //INIT $overall_kill = 0; $color = imagecolorallocate($img, $this->normalcolor_[0], $this->normalcolor_[1], $this->normalcolor_[2]); $paint_name = config::get('map_act_shownames'); $sql2 = 'select sys.sys_x, sys.sys_y, sys.sys_z, sys.sys_sec, sys.sys_id, sys.sys_name, sys.sys_id, con.con_id, con.con_name, reg.reg_id, reg.reg_name, reg.reg_x, reg.reg_z from kb3_systems sys, kb3_constellations con, kb3_regions reg where con.con_id = sys.sys_con_id and reg.reg_id = con.con_reg_id'; $sql2 .= " and reg.reg_id = " . $this->regionid2_; $xml_kills = $this->update_kill_cache(); $qry2 = new DBQuery(); $qry2->execute($sql2) or die($qry2->getErrorMsg()); while ($row2 = $qry2->getRow()) { $paint = 0; foreach ($xml_kills as $key => $value) { if ($row2['sys_id'] == $key) { $kills = $value; $paint = 1; } } if ($paint == 1) { $overall_kill = $overall_kill + $kills; //OFFSET CALCULATION $x = $row2['sys_x'] * $this->ly_; $z = $row2['sys_z'] * $this->ly_; $sys[0] = $x; $sys[1] = $z; $sys[4] = $row2['sys_id']; $sys[5] = $row2['sys_name']; $sys[6] = $row2['sys_sec']; $fp = fopen($regioncache . ".txt", "r"); // getting offset data from file $maxx = fgets($fp); $minx = fgets($fp); $maxz = fgets($fp); $minz = fgets($fp); fclose($fp); $dx = abs($maxx - $minx); $dz = abs($maxz - $minz); $xscale = 1 / ($dx / ($this->imgwidth_ - $this->offset_ * 2)); $yscale = 1 / ($dz / ($this->imgheight_ - $this->offset_ * 2)); $px = round($this->offset_ + ($sys[0] - $minx) * $xscale); $py = round($this->offset_ + ($sys[1] - $minz) * $yscale); if ($kills == 1) { // If there is only one kill we use normal highlight color $ratio = 1; if (config::get('map_act_cl_hl')) { $hscolor = explode(",", config::get('map_act_cl_hl')); $color = imagecolorallocate($img, $hscolor[0], $hscolor[1], $hscolor[2]); } else { $color = imagecolorallocate($img, '255', '209', '57'); } } else { //more then one kill... $ratio = $kills + 5; // ...then we add a bit to the ratio if (config::get('map_act_cl_hl2')) { // Set the color to Highlight 2 and the sphere color with alpha $hscolor = explode(",", config::get('map_act_cl_hl2')); $color = imagecolorallocate($img, $hscolor[0], $hscolor[1], $hscolor[2]); $color4 = imagecolorresolvealpha($img, $hscolor[0], $hscolor[1], $hscolor[2], '117'); } else { $color = imagecolorallocate($img, '255', '0', '0'); $color4 = imagecolorresolvealpha($img, 255, 0, 0, 117); } } if ($ratio > 100) { //now we limit the max-size of the sphere so it doesnt grow to big $ratio = 100; } imagefilledellipse($img, $px, $py, $ratio, $ratio, $color4); //paint the sphere -- can not use AA function cause it doesnt work with alpha imagefilledellipseaa($img, $px, $py, 6, 6, $color); // use AA function to paint the system dot if ($ratio > 10) { // extend the sphere $ratio2 = $ratio - 10; imagefilledellipse($img, $px, $py, $ratio2, $ratio2, $color4); } if ($ratio > 20) { // add another inner layer to the sphere, if it gets big enough $ratio3 = $ratio - 20; imagefilledellipse($img, $px, $py, $ratio3, $ratio3, $color4); } if ($paint_name == 1) { $tlen = 5 * strlen($sys[5]); if ($px + $tlen > $this->imgwidth_ - 20) { $sx = $px - $tlen; } else { $sx = $px + 5; } if ($py + 5 > $this->imgheight_ - 20) { $sy = $py - 5; } else { $sy = $py + 5; } imagestring($img, 1, $sx, $sy, $sys[5] . '(' . $kills . ')', $color); } } } } //--------------------------------------------------------------------------------------- // Activity end here //--------------------------------------------------------------------------------------- // Draw the region name and total kill count. if (config::get('map_act_cl_capt')) { $scolor = explode(",", config::get('map_act_cl_capt')); mapview::setcaptcolor($scolor[0], $scolor[1], $scolor[2]); } $captioncolor = imagecolorallocate($img, $this->captioncolor_[0], $this->captioncolor_[1], $this->captioncolor_[2]); switch ($this->mode_) { case "ship": case "faction": $title_kill = "Total Kills in the last hour: " . $overall_kill; break; case "activity": if (isset($this->week_)) { $title_kill = "Total Kills in Week " . $this->week_ . ": " . $overall_kill; } if (isset($this->month_)) { $title_kill = "Total Kills in " . date('F', mktime(0, 1, 0, $this->month_, 1, $this->year_)) . ": " . $overall_kill; } break; default: $title_kill = ''; break; } $str_loc = $this->imgheight_ - 10; imagestring($img, 1, 2, $str_loc, $title_kill, $captioncolor); imagestring($img, 1, 2, 2, $title_caption, $captioncolor); if ($this->mode_ == 'ship' || $this->mode_ == 'faction') { clearstatcache(); $filetime = filemtime($this->killcache); $stringpos = $this->imgwidth_ - strlen("Data from: " . date("G:i Y-m-d", $filetime)) * 5 - 5; imagestring($img, 1, $stringpos, 2, "Data from: " . date("G:i Y-m-d", $filetime), $captioncolor); } header("Content-type: image/png"); imagepng($img); }
public function resolve(string $rgb) : int { $rgb = explode('|', $rgb); $red = isset($rgb[0]) ? $rgb[0] : 0; $green = isset($rgb[1]) ? $rgb[1] : 0; $blue = isset($rgb[2]) ? $rgb[2] : 0; $alpha = isset($rgb[3]) ? $rgb[3] : 0; return imagecolorresolvealpha($this->canvas, $red, $green, $blue, $alpha); }
<?php imagecolorresolvealpha(); ?>
function Allocate($aImg, $aColor, $aAlpha = 0.0) { $res = $this->Color($aColor); if ($res === false) { return false; } list($r, $g, $b, $a) = $res; // If alpha is specified in the color string then this // takes precedence over the second argument if ($a > 0) { $aAlpha = $a; } if ($aAlpha < 0 || $aAlpha > 1) { return false; } return imagecolorresolvealpha($aImg, $r, $g, $b, round($aAlpha * 127)); }
function resolve($image) { return imagecolorresolvealpha($image, $this->red, $this->green, $this->blue, $this->alpha); }
function Allocate($aColor, $aAlpha = 0.0) { list($r, $g, $b, $a) = $this->color($aColor); // If alpha is specified in the color string then this // takes precedence over the second argument if ($a > 0) { $aAlpha = $a; } if (@$GLOBALS['gd2'] == true) { if ($aAlpha < 0 || $aAlpha > 1) { JpGraphError::Raise('Alpha parameter for color must be between 0.0 and 1.0'); exit(1); } return imagecolorresolvealpha($this->img, $r, $g, $b, round($aAlpha * 127)); } else { $index = imagecolorexact($this->img, $r, $g, $b); if ($index == -1) { $index = imagecolorallocate($this->img, $r, $g, $b); if (USE_APPROX_COLORS && $index == -1) { $index = imagecolorresolve($this->img, $r, $g, $b); } } return $index; } }
function MakeGradientFilledButtonPolygon($qualityfactor, $width_temp, $height_temp, &$actwoa, &$acthoa, $radius_temp, $color_inner, $color_outer, $text, $text_height_temp, $text_color = "black", $bkcolor = "white", $image_locate, $image_height_temp, $image_name, $image_foreground, $image_foregroundcolor, $image_transparent, $image_transparentcolor, $font_path = "") { $width = $qualityfactor * $width_temp; $height = $qualityfactor * $height_temp; $radius = $qualityfactor * $radius_temp; $text_height = $qualityfactor * $text_height_temp; $image_height = $qualityfactor * $image_height_temp; $fontname = $font_path; if ($fontname == "") { $fontname = FONT; } $baseimage = MakeFilledButtonPolygon($width, $height, $actwoa, $acthoa, $radius, $color_outer, $bkcolor); $ccolor_outer = new cColor($color_outer); $ccolor_inner = new cColor($color_inner); if ($radius > 0) { /* construct a gradient fill for this button */ for ($step = 0, $newr = $radius, $newh = $height, $neww = $width; $newr > 0; $step++, $newr--, $newh -= 2, $neww -= 2) { $newcolor = $ccolor_outer->GradientColor($ccolor_inner, 100 * sqrt(($radius - $newr) / $radius)); $overlayimage = MakeFilledButtonPolygon($neww, $newh, $actw, $acth, $newr, $newcolor->ColorHexVal()); imagecopymerge($baseimage, $overlayimage, $step, ($acthoa - $acth) / 1.5, 0, 0, $actw, $acth, 100); // imagecopymerge($baseimage, $overlayimage, $step, ($acthoa-$acth)/2, 0, 0, $actw, $acth, 100); ImageDestroy($overlayimage); } } $ctcolor = new cColor($text_color); $blk = $ctcolor->Allocate($baseimage); imagealphablending($baseimage, TRUE); // TEXT OVERLAY // find out the size of the text at that font size $txtlns = explode("\n", $text); $linecount = count($txtlns); $i = $linecount; foreach ($txtlns as $txtln) { $bbox = imagettfbbox($text_height, 0, $fontname, $txtln); $left_text = $bbox[0]; $right_text = $bbox[2]; $text_w = $right_text - $left_text; $text_x = $actwoa / 2.0 - $text_w / 2.0; if ($left_text < 0) { $text_x += abs($left_text); } // add factor for left overhang $text_y = $acthoa / 2 + $text_height / 2 * $linecount + $text_height / 6 * ($linecount - 1) - $text_height * ($i - 1) - $text_height / 3 * ($i - 1); $textlines[] = array('text' => $txtln, 'x' => $text_x, 'y' => $text_y, 'w' => $text_w); $widths[] = $text_w; $i--; } unset($txtln); $maxwidth = max($widths); // IMAGE OVERLAY $foreground_custom = strcmp($image_foreground, "custom") == 0; $foreground_auto = strcmp($image_foreground, "auto") == 0; $foreground_none = strcmp($image_foreground, "none") == 0; $transparent_custom = strcmp($image_transparent, "custom") == 0; $transparent_auto = strcmp($image_transparent, "auto") == 0; $transparent_none = strcmp($image_transparent, "none") == 0; $cicolor = new cColor("black"); if ($foreground_custom) { $cicolor = new cColor($image_foregroundcolor); } $citcolor = new cColor("white"); if ($transparent_custom) { $citcolor = new cColor($image_transparentcolor); } GetImagePaths($image_name, $img_path, $thumbpath); // $img_size = @getimagesize($img_path); $img_size = GlassyImageSize($img_path, $image_name); $img_overlay = "invalid"; switch ($img_size[2]) { case IMAGETYPE_GIF: $img_overlay = imagecreatefromgif($img_path); break; case IMAGETYPE_JPEG: $img_overlay = imagecreatefromjpeg($img_path); break; case IMAGETYPE_PNG: $img_overlay = imagecreatefrompng($img_path); break; case 99: // double-secret code for SVG $destfile = tempnam(IMGPATH, ""); @rename($destfile, $destfile . ".png"); $destfile = $destfile . ".png"; // we limit svg conversions to TWO colors only because there is no way to disable // antialiasing and antialiased images look like hell when we do color conversions // at a later step.. so, SVG images are relatively useless at this time $execarg = IMCONVERT . " -resize 10000" . "x{$image_height} -colors 2 {$img_path} {$destfile}"; @exec($execarg); $img_overlay = imagecreatefrompng($destfile); @unlink($destfile); $img_size[0] = imagesx($img_overlay); $img_size[1] = imagesy($img_overlay); break; default: break; } // image and text! $img_newh = 0; $img_neww = 0; $img_x = 0; $img_y = 0; if ($img_overlay !== "invalid") { $img_newh = $image_height; $img_neww = $img_newh * $img_size[0] / $img_size[1]; // palettize the user image if not already imagetruecolortopalette($img_overlay, FALSE, 256); // find the "foreground" color index, if configured to do so if (!$foreground_none) { $foregroundindex = imagecolorclosest($img_overlay, $cicolor->red, $cicolor->green, $cicolor->blue); // and set it to the text color if ($foregroundindex > -1) { imagecolorset($img_overlay, $foregroundindex, $ctcolor->red, $ctcolor->green, $ctcolor->blue); } } // find the transparent "background" color index, if configured to do so if (!$transparent_none) { $backgroundindex = imagecolorclosest($img_overlay, $citcolor->red, $citcolor->green, $citcolor->blue); if ($backgroundindex > -1) { imagecolortransparent($img_overlay, $backgroundindex); } } $img_y = $acthoa / 2 - $img_newh / 2; $img_x = $actwoa / 2 - $img_neww / 2; } // make adjustments for relative positions if (strcmp($image_locate, "left") == 0) { $img_x -= $maxwidth / 2 + 5; foreach ($textlines as &$textline) { $textline['x'] += $img_neww / 2; } unset($textline); } else { if (strcmp($image_locate, "right") == 0) { $img_x += $maxwidth / 2 + 5; foreach ($textlines as &$textline) { $textline['x'] -= $img_neww / 2; } unset($textline); } } if ($img_overlay !== "invalid" && strcmp($image_locate, "none") != 0) { imagecopyresampled($baseimage, $img_overlay, $img_x, $img_y, 0, 0, $img_neww, $img_newh, $img_size[0], $img_size[1]); } @imagedestroy($img_overlay); foreach ($textlines as $textline) { ImageTTFText($baseimage, $text_height, 0, $textline['x'], $textline['y'], $blk, $fontname, $textline['text']); } unset($textline); if ($radius > 0) { $radiusstart = floor($radius / 1.2); $radiuslimit = floor($radius / 2.2); $outersteps = $radiusstart - $radiuslimit; $blendfactor = 100; if ($outersteps) { $blendfactor = 100 * sqrt(1 / $outersteps); } // construct a hilight for this button // $chilitecolor = imagecolorresolvealpha ( $baseimage, 255, 255, 255, 80); for ($newr = $radiusstart; $newr >= $radiuslimit; $newr--) { $chilitecolor = imagecolorresolvealpha($baseimage, 255, 255, 255, 100 - floor(100 * ($newr - $radiuslimit) / ($radiusstart - $radiuslimit))); MyImageArc($baseimage, $radius - 1, $radius, 2 * $radiusstart, 2 * $newr, 180, 270, $chilitecolor); if ($actwoa > 2 * $radius) { ImageLine($baseimage, $radius, $radius - $newr, $actwoa - $radius - 1, $radius - $newr, $chilitecolor); } MyImageArc($baseimage, $actwoa - $radius, $radius, 2 * $radiusstart, 2 * $newr, 270, 0, $chilitecolor); } } $imagetemp = tempnam(IMGPATH, ""); ImagePNG($baseimage, $imagetemp); imagedestroy($baseimage); // experimental, fill the corners with transparent color if (strcmp(strtoupper($bkcolor), "CLEAR") == 0) { $execarg = IMMOGRIFY . " -transparent #454545 {$imagetemp}"; @exec($execarg); } if ($qualityfactor > 1) { $neww = $actwoa / $qualityfactor; $newh = $acthoa / $qualityfactor; $execarg = IMMOGRIFY . " -resize " . $neww . "x" . $newh . " {$imagetemp}"; @exec($execarg); } return $imagetemp; }