예제 #1
0
 function _TransHor3D($aGdImg, $aHorizon = 100, $aSkewDist = 120, $aDir = SKEW3D_LEFT, $aMinSize = true, $aFillColor = '#FFFFFF', $aQuality = false, $aBorder = false, $aHorizonPos = 0.5)
 {
     $w = imagesx($aGdImg);
     $h = imagesy($aGdImg);
     $hh = $h;
     if ($aMinSize) {
         $ww = ceil($w * $aHorizon / ($aSkewDist + $w));
     } else {
         $ww = $w;
     }
     $newgdh = imagecreatetruecolor($ww, $hh);
     $crgb = new RGB($newgdh);
     $fillColor = $crgb->Allocate($aFillColor);
     imagefilledrectangle($newgdh, 0, 0, $ww - 1, $hh - 1, $fillColor);
     if ($aBorder) {
         $colidx = $crgb->Allocate($aBorder);
         imagerectangle($newgdh, 0, 0, $ww - 1, $hh - 1, $colidx);
     }
     $mid = round($h * $aHorizonPos);
     $last = -1;
     for ($x = 0; $x < $w - 1; ++$x) {
         $xt = floor($x * $aHorizon / ($aSkewDist + $x));
         if (!$aQuality) {
             if ($last >= $xt) {
                 continue;
             }
             $last = $xt;
         }
         for ($y = 0; $y < $h; ++$y) {
             $yp = $h - $y - 1;
             $yt = ($yp - $mid) * $aSkewDist / ($aSkewDist + $x);
             if ($aDir == SKEW3D_RIGHT) {
                 $rgb = imagecolorat($aGdImg, $w - $x - 1, $y);
             } else {
                 $rgb = imagecolorat($aGdImg, $x, $y);
             }
             $r = $rgb >> 16 & 0xff;
             $g = $rgb >> 8 & 0xff;
             $b = $rgb & 0xff;
             $colidx = imagecolorallocate($newgdh, $r, $g, $b);
             $yt = floor($hh - $yt - $mid - 1);
             if ($aDir == SKEW3D_RIGHT) {
                 $sxt = $ww - $xt - 1;
             } else {
                 $sxt = $xt;
             }
             if (!empty($set[$xt])) {
                 $nrgb = imagecolorat($newgdh, $sxt, $yt);
                 $nr = $nrgb >> 16 & 0xff;
                 $ng = $nrgb >> 8 & 0xff;
                 $nb = $nrgb & 0xff;
                 $colidx = imagecolorallocate($newgdh, floor(($r + $nr) / 2), floor(($g + $ng) / 2), floor(($b + $nb) / 2));
             }
             imagesetpixel($newgdh, $sxt, $yt, $colidx);
         }
         $set[$xt] = true;
     }
     return $newgdh;
 }
function hideMovingObjects($imageFiles)
{
    $xMax = 0;
    $yMax = 0;
    $images = array();
    foreach ($imageFiles as $fn) {
        $images[] = imagecreatefromjpeg($fn);
        $info = getimagesize($fn);
        $infoX = $info[0];
        $infoY = $info[1];
        $infoBits = $info['bits'];
        $infoChannels = $info['channels'];
        $xMax = max($xMax, $infoX);
        $yMax = max($yMax, $infoY);
    }
    $colorGd = imagecreatetruecolor($xMax, $yMax);
    $imagesnumber = sizeof($images);
    $trimRounds = ceil(log($imagesnumber) * log($imagesnumber) / 2);
    $trimStop = $imagesnumber - $trimRounds - $trimRounds;
    //for all images and all pixel
    //calculate the Trimmed mean of color
    for ($x = 0; $x < $xMax; $x++) {
        for ($y = 0; $y < $yMax; $y++) {
            $colorR = array();
            $colorG = array();
            $colorB = array();
            foreach ($images as $img) {
                $colorRgb = imagecolorat($img, $x, $y);
                $colorR[] = RGB::getRed($colorRgb);
                $colorG[] = RGB::getGreen($colorRgb);
                $colorB[] = RGB::getBlue($colorRgb);
            }
            sort($colorR);
            sort($colorG);
            sort($colorB);
            $colorRed = avg(array_slice($colorR, $trimRounds, $trimStop));
            $colorGreen = avg(array_slice($colorG, $trimRounds, $trimStop));
            $colorBlue = avg(array_slice($colorB, $trimRounds, $trimStop));
            imagesetpixel($colorGd, $x, $y, RGB::colorSet($colorRed, $colorGreen, $colorBlue));
        }
    }
    //done return the merged image!
    //imagepng($colorGd, "last.jpg" );
    return $colorGd;
}
예제 #3
0
 function SetFillColor($aColor)
 {
     // Do an extra error check if the color is specified as an RGB array triple
     // In that case convert it to a hex string since it will otherwise be
     // interpretated as an array of colors for each individual bar.
     $aColor = RGB::tryHexConversion($aColor);
     $this->fill = true;
     $this->fill_color = $aColor;
 }
예제 #4
0
 /**
  *
  */
 function GetNextColor()
 {
     $color_list = $this->GetColorList();
     $color = null;
     if (isset($color_list[$this->color_index])) {
         $color = $color_list[$this->color_index];
     } else {
         $color_count = count($color_list);
         if ($color_count <= $this->color_index) {
             $color_tmp = $color_list[$this->color_index % $color_count];
             $brightness = 1.0 - intval($this->color_index / $color_count) * 0.2;
             $rgb = new RGB();
             $color = $color_tmp . ':' . $brightness;
             $color = $rgb->Color($color);
             $alpha = array_pop($color);
             $color = $rgb->tryHexConversion($color);
             if ($alpha) {
                 $color .= '@' . $alpha;
             }
         }
     }
     $this->color_index++;
     return $color;
 }
예제 #5
0
 /**
  * Calculate suitable colors for each defined isobar
  *
  */
 function CalculateColors()
 {
     if ($this->highcontrast) {
         if ($this->highcontrastbw) {
             for ($ib = 0; $ib < $this->nbrIsobars; $ib++) {
                 $this->isobarColors[$ib] = 'black';
             }
         } else {
             // Use only blue/red scale
             $step = round(255 / ($this->nbrIsobars - 1));
             for ($ib = 0; $ib < $this->nbrIsobars; $ib++) {
                 $this->isobarColors[$ib] = array($ib * $step, 50, 255 - $ib * $step);
             }
         }
     } else {
         $n = $this->nbrIsobars;
         $v = 0;
         $step = 1 / ($this->nbrIsobars - 1);
         for ($ib = 0; $ib < $this->nbrIsobars; $ib++) {
             $this->isobarColors[$ib] = RGB::GetSpectrum($v);
             $v += $step;
         }
     }
 }
 /**
  * Apply a jpgraph compliant color modifier on color and return a css rgb() rule
  */
 function applyColorModifier($color)
 {
     $jpgraphRgb = new RGB();
     $newColor = $jpgraphRgb->color($color . ':1.5');
     // Unset alpha channel
     unset($newColor[3]);
     // floor value to match jpgraph behaviour
     $col = implode(',', array_map('floor', $newColor));
     return 'rgb(' . $col . ')';
 }
예제 #7
0
 /**
  * Calculate suitable colors for each defined isobar
  *
  */
 function CalculateColors()
 {
     if ($this->highcontrast) {
         if ($this->highcontrastbw) {
             for ($ib = 0; $ib <= $this->nContours; $ib++) {
                 $this->contcolors[$ib] = 'black';
             }
         } else {
             // Use only blue/red scale
             $step = 255.0 / $this->nContours;
             for ($ib = 0; $ib <= $this->nContours; $ib++) {
                 $this->contcolors[$ib] = array(round($ib * $step), 50, round(255 - $ib * $step));
             }
         }
     } else {
         // This will return a basic spectrum from blue to red in even steps
         // this should probably be upgraded to our newer spectrum method introduced
         // with matrix plots
         $n = $this->nContours;
         $v = 0;
         $step = 1 / $this->nContours;
         for ($ib = 0; $ib <= $this->nContours; $ib++) {
             $this->contcolors[$ib] = RGB::GetSpectrum($v);
             $v += $step;
         }
     }
 }