public function testInvalidColor() { $strColor = '-invalid-'; $color = new Color($strColor); $this->assertEquals($strColor, $color->getColor()); $this->assertEquals(255, $color->getRed()); $this->assertEquals(255, $color->getGreen()); $this->assertEquals(255, $color->getBlue()); $this->assertEquals(0, $color->getAlpha()); }
public static function _displayPagina($accion) { $colorCookie = new Color(); if ($accion == "probarColor") { $colorCookie->probarColor(); self::$_estilo = $colorCookie->getEstilo(); } else { $colorCookie->ponerColor(); self::$_enlacesColores = "Cambio de color: <a href='./index.php?color=rojo'>Rojo</a>\n<a href='./index.php?color=azul'>Azul</a>\n<a href='./index.php?color=verde'>Verde</a>\n<a href='./index.php?color=ninguno'>Ninguno</a>"; self::$_enlace = "<a href='./index.php?accion=probarColor'>Comprobar la cookie</a>"; } self::$_color = $colorCookie->getColor(); if (isset($_COOKIE["cookieColor"]) && self::$_color != "ninguno") { self::$_mensaje = "Se ha elegido el color " . self::$_color; } else { self::$_mensaje = "No se ha elegido color"; } self::$_operacion = $colorCookie->getOperacion(); self::_retornarVista(); }
/** * @brief Resize the image to the specified width and height * * optionally keeping the aspect ratio and pads or crops the resulting * image to the desired dimensions. * * @param Integer $width The desired width * @param Integer $height The desired height * @param Integer $keepaspect One of KEEP_NONE, KEEP_CROP, and KEEP_FILL * @param Color $fillcolor The color to fill with (if KEEP_FILL) */ function resize($width, $height, $keepaspect = Canvas::KEEP_NONE, Color $fillcolor = null) { $this->checkImage(); $this->checkMeta(); $cw = imageSX($this->himage); $ch = imageSY($this->himage); $nr = (double) ($width / $height); // Get new aspect ratio $cr = (double) ($cw / $ch); // Get current aspect ratio switch ($keepaspect) { case Canvas::KEEP_NONE: $n = imagecreatetruecolor($width, $height); imagecopyresampled($n, $this->himage, 0, 0, 0, 0, $width, $height, $cw, $ch); break; case Canvas::KEEP_CROP: $ratio = $cw / $ch; if ($width / $height > $ratio) { $nh = round($width / $ratio); $nw = $width; } else { $nw = round($height * $ratio); $nh = $height; } $m = imagecreatetruecolor($nw, $nh); imagecopyresampled($m, $this->himage, 0, 0, 0, 0, $nw, $nh, $cw, $ch); $n = imagecreatetruecolor($width, $height); imagecopyresampled($n, $m, 0, 0, ($nw - $width) / 2, ($nh - $height) / 2, $width, $height, $width, $height); imagedestroy($m); break; case Canvas::KEEP_FILL: $ratio = $cw / $ch; $cw <= $width ? $nw = $cw : ($nw = $width); $nh = round($ch * $nw / $cw); if ($nh > $height) { $nw = $cw * $height / $ch; $nh = $height; } $n = imagecreatetruecolor($width, $height); imagefilledrectangle($n, 0, 0, $width, $height, $fillcolor->getColor($this->himage)); imagecopyresampled($n, $this->himage, round(($width - $nw) / 2), round(($height - $nh) / 2), 0, 0, $nw, $nh, $cw, $ch); break; } imagedestroy($this->himage); $this->himage = $n; $this->width = imageSX($this->himage); $this->height = imageSY($this->himage); }
public function testAddingHash() { $color = new Color('000000'); $this->assertEquals('#000000', $color->getColor()); $this->assertEquals('000000', $color->getColor(false)); }
function drawCircle($x, $y, $radius, Color $fillcolor, Color $linecolor = null) { $cf = $fillcolor->getColor($this->himage); imagefilledarc($this->himage, $x, $y, $radius * 2, $radius * 2, 0, 360, $cf, IMG_ARC_PIE); if ($linecolor) { $cl = $linecolor->getColor($this->himage); imagefilledarc($this->himage, $x, $y, $radius * 2, $radius * 2, 0, 360, $cl, IMG_ARC_PIE | IMG_ARC_NOFILL); } }