本文整理汇总了PHP中imagecolorexactalpha函数的典型用法代码示例。如果您正苦于以下问题:PHP imagecolorexactalpha函数的具体用法?PHP imagecolorexactalpha怎么用?PHP imagecolorexactalpha使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了imagecolorexactalpha函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: getIndex
/**
* @param resource $image GD image resource
* @return int Returns the index of the specified color+alpha in the palette of the image,
* or -1 if the color does not exist in the image's palette.
*/
public function getIndex($image)
{
if ($this->hasAlphaChannel()) {
return imagecolorexactalpha($image, $this->red, $this->green, $this->blue, $this->alpha);
} else {
return imagecolorexact($image, $this->red, $this->green, $this->blue);
}
}
示例2: transformImage
/**
* Convert resource $imges with rules from $info
*
* @param resource $image
* @param array $info
* @param array $MergedImage
* @return resource
*/
public function transformImage($image, &$info, $MergedImage = null)
{
$h = imagesy($image);
$w = imagesx($image);
//$imageTransform = $image;
if ($h != round($info['height']) || $w != round($info['width'])) {
$imageTransform = imagecreatetruecolor($info['width'], $info['height']);
imageAlphaBlending($imageTransform, false);
imagesavealpha($imageTransform, true);
imagecopyresampled($imageTransform, $image, 0, 0, 0, 0, round($info['width']), round($info['height']), $w, $h);
$image = $imageTransform;
}
//$info['rotation'] = 90;
if (!empty($info['rotation'])) {
#$col = imagecolorexactalpha ($image, 57, 57, 57, 127);
$col = imagecolorexactalpha($image, 255, 255, 255, 127);
$imageTransform = imagerotate($image, -$info['rotation'], $col);
$ims = imagecreatetruecolor(imagesx($imageTransform), imagesy($imageTransform));
imagecolortransparent($ims, $col);
imagefill($ims, 0, 0, $col);
imagecopy($ims, $imageTransform, 0, 0, 0, 0, imagesx($imageTransform), imagesy($imageTransform));
$info['x'] -= (imagesx($ims) - imagesx($image)) / 2;
$info['y'] -= (imagesy($ims) - imagesy($image)) / 2;
$image = $ims;
//imagepng($image);die();
}
$info['width'] = imagesx($image);
$info['height'] = imagesy($image);
if (!empty($MergedImage)) {
$new_image = array();
if ($info['x'] > 0) {
$info['x'] = $info['x'] + $MergedImage['areaOffsetX'];
$info['beginX'] = 0;
} else {
$info['beginX'] = -$info['x'];
$info['width'] = $info['width'] + $info['x'];
$info['x'] = $MergedImage['areaOffsetX'];
}
if ($info['y'] > 0) {
$info['y'] = $info['y'] + $MergedImage['areaOffsetY'];
$info['beginY'] = 0;
} else {
$info['beginY'] = -$info['y'];
$info['height'] = $info['height'] + $info['y'];
$info['y'] = $MergedImage['areaOffsetY'];
}
if ($info['x'] + $info['width'] > $MergedImage['areaSizeX'] + $MergedImage['areaOffsetX']) {
$info['width'] = $MergedImage['areaSizeX'] + $MergedImage['areaOffsetX'] - $info['x'];
}
if ($info['y'] + $info['height'] > $MergedImage['areaSizeY'] + $MergedImage['areaOffsetY']) {
$info['height'] = $MergedImage['areaSizeY'] + $MergedImage['areaOffsetY'] - $info['y'];
}
}
// die();
//imagepng($imageTransform);die();
return $image;
}
示例3: getColorIndex
protected function getColorIndex($v)
{
if (count($v) == 3) {
$color = imagecolorexact($this->im, $v[0], $v[1], $v[2]);
} elseif (count($v) == 4) {
$color = imagecolorexactalpha($this->im, $v[0], $v[1], $v[2], $v[3]);
}
return $color;
}
示例4: genStoneOverlay
function genStoneOverlay($rockImg, $overlayImg, $wdt, $hgt)
{
imagealphablending($rockImg, false);
imagesavealpha($rockImg, true);
$alph = imagecolorallocatealpha($rockImg, 0, 0, 0, 255);
imagefill($rockImg, 0, 0, $alph);
$color = imagecolorallocatealpha($rockImg, 0, 0, 0, 127);
imagefill($rockImg, 0, 0, $color);
for ($x = 0; $x < $wdt; $x++) {
for ($y = 0; $y < $hgt; $y++) {
$alphaIndex = imagecolorat($overlayImg, $x, $y);
$alphaColor = imagecolorsforindex($overlayImg, $alphaIndex);
$colorIndex = imagecolorat($rockImg, $x, $y);
$color = imagecolorsforindex($rockImg, $colorIndex);
$newcolor = imagecolorexactalpha($rockImg, $color['red'], $color['green'], $color['blue'], 255 - $alphaColor['red']);
if ($color == -1) {
$newcolor = imagecolorallocatealpha($rockImg, $color['red'], $color['green'], $color['blue'], 255 - $alphaColor['red']);
}
imagesetpixel($rockImg, $x, $y, $newcolor);
}
}
}
示例5: rotate
/**
* Rotate an image the given number of degrees.
*
* @param Image $image An image object. The $image->resource, $image->info['width'], and $image->info['height'] values will be modified by this call.
* @param int $degrees The number of (clockwise) degrees to rotate the image.
* @param null $background An hexadecimal integer specifying the background color to use for the uncovered area of the image after the rotation. E.g. 0x000000 for black, 0xff00ff for magenta, and 0xffffff for white. For images that support transparency, this will default to transparent. Otherwise it will be white.
* @return bool true or false, based on success.
*/
public static function rotate(Image $image, $degrees, $background = null)
{
// PHP installations using non-bundled GD do not have imagerotate.
if (!function_exists('imagerotate')) {
throw new \Exception("The image {$image->source} could not be rotated because the imagerotate() function is not available in this PHP installation.");
return false;
}
// Convert the hexadecimal background value to a color index value.
if (isset($background)) {
$rgb = array();
for ($i = 16; $i >= 0; $i -= 8) {
$rgb[] = $background >> $i & 0xff;
}
$background = imagecolorallocatealpha($image->resource, $rgb[0], $rgb[1], $rgb[2], 0);
} else {
// Set the background color as transparent if $background is NULL.
// Get the current transparent color.
$background = imagecolortransparent($image->resource);
// If no transparent colors, use white.
if ($background == 0) {
$background = imagecolorallocatealpha($image->resource, 255, 255, 255, 0);
}
}
// Images are assigned a new color palette when rotating, removing any
// transparency flags. For GIF images, keep a record of the transparent color.
if ($image->getExtension() == 'gif') {
$transparent_index = imagecolortransparent($image->resource);
if ($transparent_index != 0) {
$transparent_gif_color = imagecolorsforindex($image->resource, $transparent_index);
}
}
$image->resource = imagerotate($image->resource, 360 - $degrees, $background);
// GIFs need to reassign the transparent color after performing the rotate.
if (isset($transparent_gif_color)) {
$background = imagecolorexactalpha($image->resource, $transparent_gif_color['red'], $transparent_gif_color['green'], $transparent_gif_color['blue'], $transparent_gif_color['alpha']);
imagecolortransparent($image->resource, $background);
}
return true;
}
示例6: execute
/**
* Returns a greyscale copy of an image
*
* @param \WideImage\Image $image
* @return \WideImage\Image
*/
public function execute($image)
{
$palette = !$image->isTrueColor();
$transparent = $image->isTransparent();
if ($palette && $transparent) {
$tcrgb = $image->getTransparentColorRGB();
}
$new = $image->asTrueColor();
if (!imagefilter($new->getHandle(), IMG_FILTER_NEGATE)) {
throw new GDFunctionResultException("imagefilter() returned false");
}
if ($palette) {
$new = $new->asPalette();
if ($transparent) {
$irgb = array('red' => 255 - $tcrgb['red'], 'green' => 255 - $tcrgb['green'], 'blue' => 255 - $tcrgb['blue'], 'alpha' => 127);
// needs imagecolorexactalpha instead of imagecolorexact, otherwise doesn't work on some transparent GIF images
$new_tci = imagecolorexactalpha($new->getHandle(), $irgb['red'], $irgb['green'], $irgb['blue'], 127);
$new->setTransparentColor($new_tci);
}
}
return $new;
}
示例7: execute
/**
* {@inheritdoc}
*/
protected function execute(array $arguments)
{
// PHP installations using non-bundled GD do not have imagerotate.
if (!function_exists('imagerotate')) {
\Drupal::logger('image')->notice('The image %file could not be rotated because the imagerotate() function is not available in this PHP installation.', array('%file' => $this->getToolkit()->getImage()->getSource()));
return FALSE;
}
// Convert the hexadecimal background value to a color index value.
if (!empty($arguments['background'])) {
$rgb = array();
for ($i = 16; $i >= 0; $i -= 8) {
$rgb[] = $arguments['background'] >> $i & 0xff;
}
$arguments['background'] = imagecolorallocatealpha($this->getToolkit()->getResource(), $rgb[0], $rgb[1], $rgb[2], 0);
} else {
// Get the current transparent color.
$arguments['background'] = imagecolortransparent($this->getToolkit()->getResource());
// If no transparent colors, use white.
if ($arguments['background'] == 0) {
$arguments['background'] = imagecolorallocatealpha($this->getToolkit()->getResource(), 255, 255, 255, 0);
}
}
// Images are assigned a new color palette when rotating, removing any
// transparency flags. For GIF images, keep a record of the transparent color.
if ($this->getToolkit()->getType() == IMAGETYPE_GIF) {
$transparent_index = imagecolortransparent($this->getToolkit()->getResource());
if ($transparent_index != 0) {
$transparent_gif_color = imagecolorsforindex($this->getToolkit()->getResource(), $transparent_index);
}
}
$this->getToolkit()->setResource(imagerotate($this->getToolkit()->getResource(), 360 - $arguments['degrees'], $arguments['background']));
// GIFs need to reassign the transparent color after performing the rotate.
if (isset($transparent_gif_color)) {
$arguments['background'] = imagecolorexactalpha($this->getToolkit()->getResource(), $transparent_gif_color['red'], $transparent_gif_color['green'], $transparent_gif_color['blue'], $transparent_gif_color['alpha']);
imagecolortransparent($this->getToolkit()->getResource(), $arguments['background']);
}
return TRUE;
}
示例8: imagecreatetruecolor
<?php
$im = imagecreatetruecolor(5, 5);
$c = imagecolorexact($im, 255, 0, 255);
$c2 = imagecolorexactalpha($im, 255, 0, 255, 100);
printf("%X\n", $c);
printf("%X\n", $c2);
imagedestroy($im);
$im = imagecreate(5, 5);
$c = imagecolorallocate($im, 255, 0, 255);
$c2 = imagecolorallocate($im, 255, 200, 0);
$c3 = imagecolorallocatealpha($im, 255, 200, 0, 100);
echo imagecolorexact($im, 255, 0, 255) . "\n";
echo imagecolorexact($im, 255, 200, 0) . "\n";
echo imagecolorexactalpha($im, 255, 200, 0, 100) . "\n";
// unallocated index
echo imagecolorexact($im, 12, 12, 12) . "\n";
imagedestroy($im);
示例9: getShadow
public function getShadow($color, $alfa = 0)
{
if (isset($this->colorsrgb[$color])) {
$red = $this->colorsrgb[$color][0];
$green = $this->colorsrgb[$color][1];
$blue = $this->colorsrgb[$color][2];
} else {
list($red, $green, $blue) = hex2rgb($color);
}
if ($this->sum > 0) {
$red = (int) ($red * 0.6);
$green = (int) ($green * 0.6);
$blue = (int) ($blue * 0.6);
}
$RGB = array($red, $green, $blue);
if (isset($alfa) && function_exists('imagecolorexactalpha') && function_exists('imagecreatetruecolor') && @imagecreatetruecolor(1, 1)) {
return imagecolorexactalpha($this->im, $RGB[0], $RGB[1], $RGB[2], $alfa);
}
return imagecolorallocate($this->im, $RGB[0], $RGB[1], $RGB[2]);
}
示例10: rotate
/**
* rotates an image
* @param $degrees clockwise
* @return bool
*/
protected function rotate($degrees)
{
if (!function_exists('imagerotate')) {
$this->setError('imagerotate is not a function');
return false;
}
$ext = $this->getInfo('ext');
$width = $this->getInfo('width');
$height = $this->getInfo('height');
$bg_color = $this->getConfig('bg_color');
if ($bg_color) {
$rgb = array();
for ($i = 16; $i >= 0; $i -= 8) {
$rgb[] = $bg_color >> $i & 0xff;
}
$bg_color = imagecolorallocatealpha($this->_resource, $rgb[0], $rgb[1], $rgb[2], 0);
} else {
$bg_color = imagecolortransparent($this->_resource);
// If no transparent colors, use white.
if (0 == $bg_color) {
$bg_color = imagecolorallocatealpha($this->_resource, 255, 255, 255, 0);
}
}
if ('gif' == 'ext') {
$trans = imagecolortransparent($this->_resource);
if ($trans != 0) {
$trans_gif = imagecolorsforindex($this->_resource, $trans);
}
}
$this->_resource = imagerotate($this->_resource, 360 - $degrees, $bg_color);
if (isset($trans_gif)) {
$bg_color = imagecolorexactalpha($this->_resource, $trans_gif['red'], $trans_gif['green'], $trans_gif['blue'], $trans_gif['alpha']);
imagecolortransparent($this->_resource, $bg_color);
}
$this->_info['width'] = imagesx($this->_resource);
$this->_info['height'] = imagesy($this->_resource);
return true;
}
示例11: getExactColorAlpha
/**
* Returns the index of the color that exactly match the given color components
*
* This method accepts either each component as an integer value,
* or an associative array that holds the color's components in keys
* 'red', 'green', 'blue', 'alpha'.
*
* @param mixed $R Red component value or an associative array
* @param int $G Green component
* @param int $B Blue component
* @param int $A Alpha component
* @return int The color index
*/
function getExactColorAlpha($R, $G = null, $B = null, $A = null)
{
if (is_array($R)) {
return imagecolorexactalpha($this->handle, $R['red'], $R['green'], $R['blue'], $R['alpha']);
} else {
return imagecolorexactalpha($this->handle, $R, $G, $B, $A);
}
}
示例12: _createImageResource
function _createImageResource()
{
if ($newImage = @imagecreatefromstring($this->_headerIconFormat . $this->_imageIconFormat)) {
// Vista supports PNG.
$this->_headerIconFormat = "";
$this->_imageIconFormat = $this->_headerIconFormat . $this->_imageIconFormat;
imagesavealpha($newImage, true);
imagealphablending($newImage, false);
$this->_imageResource = $newImage;
} elseif ($this->_entry["Height"] <= 1024 && $this->_entry["Width"] <= 1024) {
$newImage = imagecreatetruecolor($this->_entry["Width"], $this->_entry["Height"]);
imagesavealpha($newImage, true);
imagealphablending($newImage, false);
$readPosition = 0;
$palette = array();
if ($this->_header["BitCount"] < 24) {
// Read Palette for low bitcounts
$colorsInPalette = $this->_header["ColorsUsed"] ? $this->_header["ColorsUsed"] : $this->_entry["ColorCount"];
for ($t = 0; $t < pow(2, $this->_header["BitCount"]); $t++) {
$blue = ord($this->_imageIconFormat[$readPosition++]);
$green = ord($this->_imageIconFormat[$readPosition++]);
$red = ord($this->_imageIconFormat[$readPosition++]);
$readPosition++;
// Unused "Reserved" value.
$existingPaletteEntry = imagecolorexactalpha($newImage, $red, $green, $blue, 0);
if ($existingPaletteEntry >= 0) {
$palette[] = $existingPaletteEntry;
} else {
$palette[] = imagecolorallocatealpha($newImage, $red, $green, $blue, 0);
}
}
// XOR
for ($y = 0; $y < $this->_entry["Height"]; $y++) {
$colors = array();
for ($x = 0; $x < $this->_entry["Width"]; $x++) {
if ($this->_header["BitCount"] < 8) {
$color = array_shift($colors);
if (is_null($color)) {
$byte = ord($this->_imageIconFormat[$readPosition++]);
$tmp_color = 0;
for ($t = 7; $t >= 0; $t--) {
$bit_value = pow(2, $t);
$bit = floor($byte / $bit_value);
$byte = $byte - $bit * $bit_value;
$tmp_color += $bit * pow(2, $t % $this->_header["BitCount"]);
if ($t % $this->_header["BitCount"] == 0) {
array_push($colors, $tmp_color);
$tmp_color = 0;
}
}
$color = array_shift($colors);
}
} else {
$color = ord($this->_imageIconFormat[$readPosition++]);
}
imagesetpixel($newImage, $x, $this->_entry["Height"] - $y - 1, $palette[$color]) or die("can't set pixel");
}
// All rows end on the 32 bit
if ($readPosition % 4) {
$readPosition += 4 - $readPosition % 4;
}
}
} else {
// BitCount >= 24, No Palette.
// marking position because some icons mark all pixels transparent when using an AND map.
$markPosition = $readPosition;
$retry = true;
$ignoreAlpha = false;
while ($retry) {
$alphas = array();
$retry = false;
for ($y = 0; $y < $this->_entry["Height"] and !$retry; $y++) {
for ($x = 0; $x < $this->_entry["Width"] and !$retry; $x++) {
$blue = ord($this->_imageIconFormat[$readPosition++]);
$green = ord($this->_imageIconFormat[$readPosition++]);
$red = ord($this->_imageIconFormat[$readPosition++]);
if ($this->_header["BitCount"] < 32) {
$alpha = 0;
} elseif ($ignoreAlpha) {
$alpha = 0;
$readPosition++;
} else {
$alpha = ord($this->_imageIconFormat[$readPosition++]);
$alphas[$alpha] = $alpha;
$alpha = 127 - round($alpha / 255 * 127);
}
$paletteEntry = imagecolorexactalpha($newImage, $red, $green, $blue, $alpha);
if ($paletteEntry < 0) {
$paletteEntry = imagecolorallocatealpha($newImage, $red, $green, $blue, $alpha);
}
imagesetpixel($newImage, $x, $this->_entry["Height"] - $y - 1, $paletteEntry) or die("can't set pixel");
}
if ($readPosition % 4) {
$readPosition += 4 - $readPosition % 4;
}
}
if ($this->_header["BitCount"] == 32 && isset($alphas[0]) && count($alphas) == 1) {
$retry = true;
$readPosition = $markPosition;
$ignoreAlpha = true;
//.........这里部分代码省略.........
示例13: allocate
/**
* Allocates a color
*
* This function tries to allocate the requested color. If the color
* already exists in the imaga it will be reused.
*
* @param ezcGraphColor $color
* @return int Color index
*/
protected function allocate(ezcGraphColor $color)
{
$image = $this->getImage();
if ($color->alpha > 0) {
$fetched = imagecolorexactalpha($image, $color->red, $color->green, $color->blue, $color->alpha / 2);
if ($fetched < 0) {
$fetched = imagecolorallocatealpha($image, $color->red, $color->green, $color->blue, $color->alpha / 2);
}
return $fetched;
} else {
$fetched = imagecolorexact($image, $color->red, $color->green, $color->blue);
if ($fetched < 0) {
$fetched = imagecolorallocate($image, $color->red, $color->green, $color->blue);
}
return $fetched;
}
}
示例14: imagefilledellipseaa
public static function imagefilledellipseaa(&$im, $CX, $CY, $Width, $Height, $color)
{
$XRadius = floor($Width / 2);
$YRadius = floor($Height / 2);
$baseColor = self::color2rgb($color);
$TwoASquare = 2 * $XRadius * $XRadius;
$TwoBSquare = 2 * $YRadius * $YRadius;
$X = $XRadius;
$Y = 0;
$XChange = $YRadius * $YRadius * (1 - 2 * $XRadius);
$YChange = $XRadius * $XRadius;
$EllipseError = 0;
$StoppingX = $TwoBSquare * $XRadius;
$StoppingY = 0;
$alpha = 77;
$color = imagecolorexactalpha($im, $baseColor[0], $baseColor[1], $baseColor[2], $alpha);
while ($StoppingX >= $StoppingY) {
// {1st set of points, y' > -1}
self::imagefilledellipseaa_Plot4EllipsePoints($im, $CX, $CY, $X, $Y, $color, 0);
$Y++;
$StoppingY += $TwoASquare;
$EllipseError += $YChange;
$YChange += $TwoASquare;
if (2 * $EllipseError + $XChange > 0) {
$X--;
$StoppingX -= $TwoBSquare;
$EllipseError += $XChange;
$XChange += $TwoBSquare;
}
// decide how much of pixel is filled.
$filled = $X - sqrt($XRadius * $XRadius - $XRadius * $XRadius / ($YRadius * $YRadius) * $Y * $Y);
$alpha = abs(90 * $filled + 37);
imagecolordeallocate($im, $color);
$color = imagecolorexactalpha($im, $baseColor[0], $baseColor[1], $baseColor[2], $alpha);
}
// { 1st point set is done; start the 2nd set of points }
$X = 0;
$Y = $YRadius;
$XChange = $YRadius * $YRadius;
$YChange = $XRadius * $XRadius * (1 - 2 * $YRadius);
$EllipseError = 0;
$StoppingX = 0;
$StoppingY = $TwoASquare * $YRadius;
$alpha = 77;
$color = imagecolorexactalpha($im, $baseColor[0], $baseColor[1], $baseColor[2], $alpha);
while ($StoppingX <= $StoppingY) {
// {2nd set of points, y' < -1}
self::imagefilledellipseaa_Plot4EllipsePoints($im, $CX, $CY, $X, $Y, $color, 1);
$X++;
$StoppingX += $TwoBSquare;
$EllipseError += $XChange;
$XChange += $TwoBSquare;
if (2 * $EllipseError + $YChange > 0) {
$Y--;
$StoppingY -= $TwoASquare;
$EllipseError += $YChange;
$YChange += $TwoASquare;
}
// decide how much of pixel is filled.
$filled = $Y - sqrt($YRadius * $YRadius - $YRadius * $YRadius / ($XRadius * $XRadius) * $X * $X);
$alpha = abs(90 * $filled + 37);
imagecolordeallocate($im, $color);
$color = imagecolorexactalpha($im, $baseColor[0], $baseColor[1], $baseColor[2], $alpha);
}
}
示例15: Rotate
/**
* Rotate an image.
* @param string $srcfile The source image.
* @param string $dstfile The destination file.
* @param float $angle Rotation angle, in degrees. The rotation angle is interpreted as the number of degrees to rotate the image anticlockwise.
*/
public static function Rotate($srcfile, $dstfile, $angle)
{
// load data from image file; on fail, return source filename
list($data, $size) = self::_GetFileData($srcfile);
if (is_null($data)) {
return $srcfile;
}
// get image type
$type = $size[2];
// rotate the image and save it
switch ($type) {
case 1:
// this is needed because there's a bug in GD:
// when you rotate transparent GIFs by multiples
// of 90 degrees, the transparency is lost
$index = imagecolortransparent($data);
if ($index >= 0) {
$color = imagecolorsforindex($data, $index);
$index = imagecolorallocate($data, $color['red'], $color['green'], $color['blue']);
$rotated = imagerotate($data, $angle, $index);
$index = imagecolorexactalpha($rotated, $color['red'], $color['green'], $color['blue'], $color['alpha']);
imagecolortransparent($rotated, $index);
} else {
$rotated = imagerotate($data, $angle, 0);
}
imagegif($rotated, $dstfile);
break;
case 3:
$rotated = imagerotate($data, $angle, -1);
imagealphablending($rotated, true);
imagesavealpha($rotated, true);
imagepng($rotated, $dstfile);
break;
default:
$rotated = imagerotate($data, $angle, 0);
imagejpeg($rotated, $dstfile, 100);
break;
}
// return destination filename
return $dstfile;
}