本文整理汇总了PHP中imagecolorexactalpha函数的典型用法代码示例。如果您正苦于以下问题:PHP imagecolorexactalpha函数的具体用法?PHP imagecolorexactalpha怎么用?PHP imagecolorexactalpha使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了imagecolorexactalpha函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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);
}
}
开发者ID:si2info,项目名称:cinda-server,代码行数:13,代码来源:Color.php
示例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;
}
开发者ID:Eximagen,项目名称:BulletMagento,代码行数:65,代码来源:Transform.php
示例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;
}
开发者ID:shapik2004,项目名称:album2,代码行数:9,代码来源:Box.php
示例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);
}
}
}
开发者ID:ridixcr,项目名称:vintagecraft,代码行数:22,代码来源:genstoneoverlays.php
示例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;
}
开发者ID:asins,项目名称:imagecache,代码行数:47,代码来源:Gd.php
示例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;
}
开发者ID:nooshin-mirzadeh,项目名称:web_2.0_benchmark,代码行数:28,代码来源:AsNegative.php
示例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;
}
开发者ID:alnutile,项目名称:drunatra,代码行数:41,代码来源:Rotate.php
示例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);
开发者ID:badlamer,项目名称:hhvm,代码行数:18,代码来源:colorexact.php
示例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]);
}
开发者ID:quanta-computing,项目名称:debian-packages,代码行数:20,代码来源:class.cgraphdraw.php
示例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;
}
开发者ID:ctpmp,项目名称:onephile,代码行数:43,代码来源:Img.php
示例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);
}
}
开发者ID:FabiolaBraga,项目名称:kandaframework,代码行数:21,代码来源:WideImage_TrueColorImage.php
示例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;
//.........这里部分代码省略.........
开发者ID:mm999,项目名称:selfoss,代码行数:101,代码来源:floIcon.php
示例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;
}
}
开发者ID:mediasadc,项目名称:alba,代码行数:26,代码来源:gd.php
示例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);
}
}
开发者ID:hkilter,项目名称:OpenSupplyChains,代码行数:65,代码来源:static.php
示例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;
}
开发者ID:ssrsfs,项目名称:blg,代码行数:47,代码来源:Gdi.php
示例16: createTransparentImage
private function createTransparentImage($width, $height)
{
$img = imagecreatetruecolor($width, $height);
$white = imagecolorexactalpha($img, 255, 255, 255, 127);
imagefill($img, 0, 0, $white);
imagealphablending($img, false);
$bg = imagecolorallocate($img, 0, 0, 0);
imagecolortransparent($img, $bg);
imagesavealpha($img, true);
return $img;
}
开发者ID:Dhrumil1808,项目名称:php-spriter,代码行数:11,代码来源:spriter.class.php
示例17: _readIconResource
/**
* Extracts icon resource
* @return GD2 resource
*/
private static function _readIconResource($fp, $idx)
{
$entry = self::_readIconEntry($fp, $idx);
fseek($fp, $entry['ImageOffset']);
if ($entry['Reserved'] != 0) {
throw new \Exception('Reserved (0) is ' . $entry['Reserved']);
}
if ($entry['Planes'] > 1) {
throw new \Exception('odd planes: ' . $entry['Planes']);
}
// read icon data
$data = fread($fp, $entry['BytesInRes']);
//file_put_contents('dump-'.($idx+1).'.raw', $data);
if (substr($data, 0, 4) == chr(0x89) . 'PNG') {
$im = imagecreatefromstring($data);
imagesavealpha($im, true);
imagealphablending($im, false);
return $im;
}
// read BITMAPINFOHEADER
$header = unpack('VSize/VWidth/VHeight/vPlanes/vBitCount/VCompression/VImageSize/VXpixelsPerM/VYpixelsPerM/VColorsUsed/VColorsImportant', substr($data, 0, 40));
if ($header['Size'] != 40) {
print_r($header);
throw new \Exception('odd header size: ' . $header['Size']);
}
if ($header['Planes'] > 1) {
throw new \Exception('odd planes: ' . $header['Planes']);
}
if ($header['Compression']) {
throw new \Exception('compression not supported');
}
if ($entry['Height'] > 1024 || $entry['Width'] > 1024) {
throw new \Exception('xxx too big');
}
$im = imagecreatetruecolor($entry['Width'], $entry['Height']);
imagesavealpha($im, true);
imagealphablending($im, false);
$pos = 40;
$palette = array();
if ($header['BitCount'] < 24) {
// Read Palette for low bitcounts
$pal_entries = $entry['ColorCount'];
if (!$entry['ColorCount'] && $header['BitCount'] == 8) {
$pal_entries = 256;
}
for ($i = 0; $i < $pal_entries; $i++) {
$b = ord($data[$pos++]);
$g = ord($data[$pos++]);
$r = ord($data[$pos++]);
$pos++;
// skip empty alpha channel
$col = imagecolorexactalpha($im, $r, $g, $b, 0);
// echo '0x'.dechex($entry['ImageOffset'] + 40 + $pos-4).': Color '.$i.' '.dechex($r).','.dechex($g).','.dechex($b)."\n";
if ($col >= 0) {
$palette[] = $col;
} else {
$palette[] = imagecolorallocatealpha($im, $r, $g, $b, 0);
}
}
// XorMap (contains the icon's foreground bitmap) Each value is an index into the Palette color map
for ($y = 0; $y < $entry['Height']; $y++) {
$colors = array();
for ($x = 0; $x < $entry['Width']; $x++) {
switch ($header['BitCount']) {
case 4:
// 8- and 16-color bitmap data is stored as 4 bits per pixel
list($hi, $lo) = byte_split($data[$pos++]);
imagesetpixel($im, $x, $entry['Height'] - $y - 1, $palette[$hi]);
imagesetpixel($im, $x + 1, $entry['Height'] - $y - 1, $palette[$lo]);
$x++;
// echo '0x'.dechex($pos-1).': XorMap '.$hi.', '.$lo."\n";
break;
case 8:
if ($entry['ColorCount']) {
throw new \Exception('xxx use available palette for 8bit??');
}
$byte = ord($data[$pos++]);
imagesetpixel($im, $x, $entry['Height'] - $y - 1, $palette[$byte]);
// echo '0x'.dechex($pos-1).': XorMap 0x'.dechex($byte)."\n";
break;
default:
throw new \Exception('unhandled bitcount ' . $header['BitCount']);
}
}
// All rows end on the 32 bit
if ($pos % 4) {
$pos += 4 - $pos % 4;
}
}
} else {
// BitCount >= 24, No Palette
// marking position because some icons mark all pixels transparent when using an AND map.
$mark_pos = $pos;
$use_alpha = false;
$alphas = array();
for ($y = 0; $y < $entry['Height']; $y++) {
//.........这里部分代码省略.........
开发者ID:martinlindhe,项目名称:core_dev,代码行数:101,代码来源:IconReader.php
示例18: createTransparent
function createTransparent($x, $y)
{
$this->resample = false;
$temp = $this->copycreatehandle($this->handle, 0, 0, 0, 0, $this->width, $this->height, $this->width, $this->height);
$rgb = imagecolorat($temp, $x, $y);
if ($this->output == "png8") {
imagecolortransparent($temp, $rgb);
} else {
imagecolorexactalpha($temp, $rgb["red"], $rgb["green"], $rgb["blue"], 127);
}
return $this->createUnique($temp);
}
开发者ID:andrewroth,项目名称:c4c_intranet,代码行数:12,代码来源:index.php
示例19: acolor2color
function acolor2color($im, $acolor, $alpha = false)
{
if ($alpha) {
return imagecolorexactalpha($im, $acolor[0], $acolor[1], $acolor[2], $acolor[3]);
} else {
return imagecolorallocate($im, $acolor[0], $acolor[1], $acolor[2]);
}
}
开发者ID:splitbrain,项目名称:dokuwiki-plugin-godiag,代码行数:8,代码来源:syntax.php
示例20: allocateColor
/**
* Allocate a color for an image.
*
* @param int $red Value of red component (between 0 and 255)
* @param int $green Value of green component (between 0 and 255)
* @param int $blue Value of blue component (between 0 and 255)
* @param int|null $alpha Optional value of alpha component (between 0 and 127). 0 = opaque, 127 = transparent.
*
* @return Color
*/
public function allocateColor($red, $green, $blue, $alpha = null)
{
// Verify parameters before trying to allocate
new Color($red, $green, $blue, $alpha);
// Reuse same color if its already in index
if ($alpha === null) {
$index = imagecolorexact($this->resource, $red, $green, $blue);
} else {
$index = imagecolorexactalpha($this->resource, $red, $green, $blue, $alpha);
}
if ($index !== -1) {
return new Color($red, $green, $blue, $alpha, $index);
}
// Allocate new color
if ($alpha === null) {
$index = imagecolorallocate($this->resource, $red, $green, $blue);
} else {
$index = imagecolorallocatealpha($this->resource, $red, $green, $blue, $alpha);
}
if ($index === false) {
throw new InvalidArgumentException('Failed to create color');
}
return new Color($red, $green, $blue, $alpha, $index);
}
开发者ID:pkdevboxy,项目名称:bolt-thumbs,代码行数:34,代码来源:ImageResource.php
注:本文中的imagecolorexactalpha函数示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论