本文整理汇总了PHP中ImageColorAllocateAlpha函数的典型用法代码示例。如果您正苦于以下问题:PHP ImageColorAllocateAlpha函数的具体用法?PHP ImageColorAllocateAlpha怎么用?PHP ImageColorAllocateAlpha使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了ImageColorAllocateAlpha函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: canvas
function canvas ($width,$height,$alpha=false) {
$this->processed = ImageCreateTrueColor($width,$height);
if ($alpha) {
ImageAlphaBlending($this->processed, false);
$transparent = ImageColorAllocateAlpha($this->processed, 0, 0, 0, 127);
ImageFill($this->processed, 0, 0, $transparent);
ImageSaveAlpha($this->processed, true);
$this->alpha = true;
}
}
示例2: __construct
function __construct()
{
header('Pragma: public');
header('Cache-Control: max-age=86400');
header('Expires: ' . gmdate('D, d M Y H:i:s \\G\\M\\T', time() + 86400));
header('Content-Type: image/png');
$this->image = ImageCreateTrueColor(96, 96);
ImageSaveAlpha($this->image, true);
ImageFill($this->image, 0, 0, ImageColorAllocateAlpha($this->image, 0, 0, 0, 127));
}
示例3: imageConvolution
function imageConvolution($src, $filter, $filter_div, $offset)
{
if ($src == NULL) {
return 0;
}
$sx = imagesx($src);
$sy = imagesy($src);
$srcback = ImageCreateTrueColor($sx, $sy);
ImageAlphaBlending($srcback, false);
ImageAlphaBlending($src, false);
ImageCopy($srcback, $src, 0, 0, 0, 0, $sx, $sy);
if ($srcback == NULL) {
return 0;
}
for ($y = 0; $y < $sy; ++$y) {
for ($x = 0; $x < $sx; ++$x) {
$new_r = $new_g = $new_b = 0;
$alpha = imagecolorat($srcback, @$pxl[0], @$pxl[1]);
$new_a = $alpha >> 24;
for ($j = 0; $j < 3; ++$j) {
$yv = min(max($y - 1 + $j, 0), $sy - 1);
for ($i = 0; $i < 3; ++$i) {
$pxl = array(min(max($x - 1 + $i, 0), $sx - 1), $yv);
$rgb = imagecolorat($srcback, $pxl[0], $pxl[1]);
$new_r += ($rgb >> 16 & 0xff) * $filter[$j][$i];
$new_g += ($rgb >> 8 & 0xff) * $filter[$j][$i];
$new_b += ($rgb & 0xff) * $filter[$j][$i];
$new_a += ((0x7f000000 & $rgb) >> 24) * $filter[$j][$i];
}
}
$new_r = $new_r / $filter_div + $offset;
$new_g = $new_g / $filter_div + $offset;
$new_b = $new_b / $filter_div + $offset;
$new_a = $new_a / $filter_div + $offset;
$new_r = $new_r > 255 ? 255 : ($new_r < 0 ? 0 : $new_r);
$new_g = $new_g > 255 ? 255 : ($new_g < 0 ? 0 : $new_g);
$new_b = $new_b > 255 ? 255 : ($new_b < 0 ? 0 : $new_b);
$new_a = $new_a > 127 ? 127 : ($new_a < 0 ? 0 : $new_a);
$new_pxl = ImageColorAllocateAlpha($src, (int) $new_r, (int) $new_g, (int) $new_b, $new_a);
if ($new_pxl == -1) {
$new_pxl = ImageColorClosestAlpha($src, (int) $new_r, (int) $new_g, (int) $new_b, $new_a);
}
if ($y >= 0 && $y < $sy) {
imagesetpixel($src, $x, $y, $new_pxl);
}
}
}
imagedestroy($srcback);
return 1;
}
示例4: show_image
public function show_image($width = 88, $height = 31) {
if (isSet($this->tt_font)) {
if (!file_exists($this->tt_font))
exit('The path to the true type font is incorrect.');
}
if ($this->chars_number < 3)
exit('The captcha code must have at least 3 characters');
$string = $this->generate_string();
$im = ImageCreate($width, $height);
/* Set a White & Transparent Background Color */
$bg = ImageColorAllocateAlpha($im, 255, 255, 255, 127); // (PHP 4 >= 4.3.2, PHP 5)
ImageFill($im, 0, 0, $bg);
/* Border Color */
if ($this->border_color) {
list($red, $green, $blue) = explode(',', $this->border_color);
$border = ImageColorAllocate($im, $red, $green, $blue);
ImageRectangle($im, 0, 0, $width - 1, $height - 1, $border);
}
$textcolor = ImageColorAllocate($im, 191, 120, 120);
$y = 24;
for ($i = 0; $i < $this->chars_number; $i++) {
$char = $string[$i];
$factor = 15;
$x = ($factor * ($i + 1)) - 6;
$angle = rand(1, 15);
imagettftext($im, $this->font_size, $angle, $x, $y, $textcolor, $this->tt_font, $char);
}
$_SESSION['security_code'] = md5($string);
/* Output the verification image */
header("Content-type: image/png");
ImagePNG($im);
exit;
}
示例5: ImageSY
$yi = ImageSY($image);
// find the size of the text
$box = ImageFTBBox($size, $angle, $font, $text, $extrainfo);
$xr = abs(max($box[2], $box[4]));
$yr = abs(max($box[5], $box[7]));
// compute centering
$x = intval(($xi - $xr) / 2);
$y = intval(($yi + $yr) / 2);
return array($x, $y);
}
$_GET['text'] = 'I <3 PHP!';
// Configuration settings
$image = ImageCreateFromPNG(__DIR__ . '/button.png');
$text = $_GET['text'];
$font = '/Library/Fonts/Hei.ttf';
$size = 24;
$color = 0x0;
$angle = 0;
// Print-centered text
list($x, $y) = ImageFTCenter($image, $size, $angle, $font, $text);
ImageFTText($image, $size, $angle, $x, $y, $color, $font, $text);
// Preserve Transparency
ImageColorTransparent($image, ImageColorAllocateAlpha($image, 0, 0, 0, 127));
ImageAlphaBlending($image, false);
ImageSaveAlpha($image, true);
// Send image
header('Content-type: image/png');
ImagePNG($image);
// Clean up
ImagePSFreeFont($font);
ImageDestroy($image);
示例6: floatval
<?php
$p = floatval($_REQUEST['p']);
header("Content-type: image/png");
$im = imagecreatetruecolor(320, 240);
imagealphablending($im, false);
imagesavealpha($im, true);
$bg = ImageColorAllocateAlpha($im, 255, 255, 255, 127);
// (PHP 4 >= 4.3.2, PHP 5)
ImageFill($im, 0, 0, $bg);
$ink = imagecolorallocate($im, 255, 216, 132);
imagefilledellipse($im, 160, 120, 200, 150, $ink);
$ink = imagecolorallocate($im, 224, 144, 0);
imagefilledarc($im, 160, 120, 200, 150, 0, 360 * $p, $ink, IMG_ARC_PIE);
$ink = imagecolorallocate($im, 255, 255, 255);
//
imagestring($im, 5, 160, 120, strval(intval($p * 100)) . "%", $ink);
imagepng($im);
imagedestroy($im);
示例7: image_histogramme
/**
* Generer un histrogramme des couleurs RVB de l'image
*
* @param object $im
* @return string
*/
function image_histogramme($im)
{
include_spip("inc/filtres_images");
$fonction = array('image_histo', func_get_args());
$image = image_valeurs_trans($im, "histo", "png", $fonction);
if (!$image) {
return "";
}
$x_i = $image["largeur"];
$y_i = $image["hauteur"];
$surface = $x_i * $y_i;
if (!test_traiter_image($image["fichier"], $x_i, $y_i)) {
return;
}
$im = $image["fichier"];
$dest = $image["fichier_dest"];
$creer = $image["creer"];
if ($creer) {
$im = $image["fonction_imagecreatefrom"]($im);
$im_ = imagecreatetruecolor(258, 130);
@imagealphablending($im_, false);
@imagesavealpha($im_, true);
$color_t = ImageColorAllocateAlpha($im_, 255, 255, 255, 50);
imagefill($im_, 0, 0, $color_t);
$col_poly = imagecolorallocate($im_, 60, 60, 60);
imagepolygon($im_, array(0, 0, 257, 0, 257, 129, 0, 129), 4, $col_poly);
$val_gris = $val_r = $val_g = $val_b = array();
for ($x = 0; $x < $x_i; $x++) {
for ($y = 0; $y < $y_i; $y++) {
$rgb = ImageColorAt($im, $x, $y);
$a = $rgb >> 24 & 0xff;
$r = $rgb >> 16 & 0xff;
$g = $rgb >> 8 & 0xff;
$b = $rgb & 0xff;
$a = (127 - $a) / 127;
$a = 1;
$gris = round($a * ($r + $g + $b) / 3);
$r = round($a * $r);
$g = round($a * $g);
$b = round($a * $b);
$val_gris[$gris]++;
$val_r[$r]++;
$val_g[$g]++;
$val_b[$b]++;
}
}
$max = max(max($val_gris), max($val_r), max($val_g), max($val_b));
// Limiter Max si trop concentr'e
$max = min($max, round($surface * 0.03));
$rapport = 127 / $max;
$gris_50 = imagecolorallocate($im_, 170, 170, 170);
$gris_70 = imagecolorallocate($im_, 60, 60, 60);
for ($i = 0; $i < 256; $i++) {
$val = 127 - round(max(0, $val_gris[$i]) * $rapport);
imageline($im_, $i + 1, 128, $i + 1, $val + 1, $gris_50);
imagesetpixel($im_, $i + 1, $val + 1, $gris_70);
}
$bleu = imagecolorallocate($im_, 0, 0, 255);
for ($i = 0; $i < 256; $i++) {
$val = 127 - round(max(0, $val_b[$i]) * $rapport);
if ($i == 0) {
imagesetpixel($im_, $i + 1, $val + 1, $bleu);
} else {
imageline($im_, $i, $val_old + 1, $i + 1, $val + 1, $bleu);
}
$val_old = $val;
}
$green = imagecolorallocate($im_, 0, 255, 0);
for ($i = 0; $i < 256; $i++) {
$val = 127 - round(max(0, $val_g[$i]) * $rapport);
if ($i == 0) {
imagesetpixel($im_, $i + 1, $val + 1, $green);
} else {
imageline($im_, $i, $val_old + 1, $i + 1, $val + 1, $green);
}
$val_old = $val;
}
$rouge = imagecolorallocate($im_, 255, 0, 0);
for ($i = 0; $i < 256; $i++) {
$val = 127 - round(max(0, $val_r[$i]) * $rapport);
if ($i == 0) {
imagesetpixel($im_, $i + 1, $val + 1, $rouge);
} else {
imageline($im_, $i, $val_old + 1, $i + 1, $val + 1, $rouge);
}
$val_old = $val;
}
$image["fonction_image"]($im_, "{$dest}");
imagedestroy($im_);
imagedestroy($im);
}
return _image_ecrire_tag($image, array('src' => $dest, 'width' => 258, 'height' => 130));
}
示例8: text
public function text($text, $x = 0, $y = 0, $font = '', $font_size = 18)
{
$box = ImageTTFBbox($font_size, 0, $font, $text);
$text_width = abs($box[4] - $box[0]);
$text_height = abs($box[5] - $box[1]);
$wm = @ImageCreateTrueColor($text_width, $text_height);
ImageAlphaBlending($wm, FALSE);
if ($this->background_color) {
$bgcolor = $this->background_color;
} else {
$bgcolor = ImageColorAllocateAlpha($wm, 0, 0, 0, 127);
}
ImageFilledRectangle($wm, 0, 0, $text_width, $text_height, $bgcolor);
ImageAlphaBlending($wm, TRUE);
if ($this->text_color) {
$color = $this->text_color;
} else {
$color = ImageColorAllocateAlpha($wm, 0, 0, 0, 0);
}
ImageTTFText($wm, $font_size, 0, 0, $text_height - 2, $color, $font, $text);
ImageAlphaBlending($this->im, TRUE);
ImageCopy($this->im, $wm, $x, $y, 0, 0, $text_width, $text_height);
}
示例9: GenerateCaptcha
public static function GenerateCaptcha()
{
if (isset($_SESSION['generated_captcha'])) {
Session::UnsetKeys(array('generated_captcha'));
}
$InitialString = str_shuffle("abcdefghijklmnopqrstuvwxyz1234567890");
$RandomString = substr($InitialString, 0, 9);
$CreateBlankImage = ImageCreate(200, 70) or die("Cannot Initialize new GD image stream");
$BackgroundColor = ImageColorAllocateAlpha($CreateBlankImage, 255, 255, 255, 127);
imagefill($CreateBlankImage, 0, 0, 0x7fff0000);
$BackgroundColor = ImageColorAllocate($CreateBlankImage, 204, 255, 51);
$TextColor = ImageColorAllocate($CreateBlankImage, 51, 51, 255);
ImageString($CreateBlankImage, 5, 50, 25, $RandomString, $TextColor);
ImagePng($CreateBlankImage);
$_SESSION['generated_captcha'] = $RandomString;
Session::UpdateSession($_SESSION);
}
示例10: ImageColorAllocateAlphaSafe
function ImageColorAllocateAlphaSafe(&$gdimg_hexcolorallocate, $R, $G, $B, $alpha = false)
{
if (phpthumb_functions::version_compare_replacement(phpversion(), '4.3.2', '>=') && $alpha !== false) {
return ImageColorAllocateAlpha($gdimg_hexcolorallocate, $R, $G, $B, intval($alpha));
} else {
return ImageColorAllocate($gdimg_hexcolorallocate, $R, $G, $B);
}
}
示例11: ImageCreateTrueColor
$image = ImageCreateTrueColor(400, 300);
ImageAlphaBlending($image, true);
// allocate some colors
$black = ImageColorAllocate($image, 0, 0, 0);
$red = ImageColorAllocate($image, 0xff, 0, 0);
$green = ImageColorAllocate($image, 0, 0xff, 0);
$blue = ImageColorAllocate($image, 0, 0, 0xff);
$white = ImageColorAllocate($image, 0xff, 0xff, 0xff);
// create a frame
ImageFilledRectangle($image, 0, 0, 399, 299, $white);
ImageRectangle($image, 0, 0, 399, 299, $black);
// draw some lines
ImageLine($image, 200, 50, 350, 150, $red);
ImageLine($image, 200, 60, 350, 160, $green);
ImageLine($image, 200, 70, 350, 170, $blue);
// draw some overlapping alpha blended boxes
$redAlpha = ImageColorAllocateAlpha($image, 0xff, 0, 0, 75);
$blueAlpha = ImageColorAllocateAlpha($image, 0, 0xff, 0, 75);
$greenAlpha = ImageColorAllocateAlpha($image, 0, 0, 0xff, 75);
ImageFilledRectangle($image, 50, 50, 90, 90, $redAlpha);
ImageFilledRectangle($image, 60, 80, 100, 120, $greenAlpha);
ImageFilledRectangle($image, 80, 60, 120, 100, $blueAlpha);
// write some _default_ text
for ($font = 1; $font <= 5; $font++) {
ImageString($image, $font, 50, 150 + $font * 20, 'Testing GD output', $black);
}
ImageString($image, 3, 51, 21, 'Congratulations! The GD2 installation works', $black);
ImageString($image, 3, 50, 20, 'Congratulations! The GD2 installation works', $red);
// output the test image
header('Content-Type: image/png');
ImagePNG($image);
示例12: init
function init($w, $h, $d)
{
$this->im = ImageCreate($w, $h);
imagesavealpha($this->im, true);
$this->width = $w;
$this->height = $h;
$this->data = $d;
$this->da_width = $this->width - $this->left - $this->right;
$this->da_height = $this->height - $this->top - $this->bottom;
$this->center_x = intval($this->left + $this->da_width / 2);
$this->center_y = intval($this->top + $this->da_height / 2);
/* font sizes */
$this->fx = array(0, 5, 6, 7, 8, 9);
$this->fy = array(0, 7, 8, 10, 14, 11);
/* decide the diameter of the pie */
if ($this->da_height > $this->da_width) {
$this->diameter = $this->da_width;
} else {
$this->diameter = $this->da_height;
}
$this->white = ImageColorAllocateAlpha($this->im, 0, 0, 0, 127);
imagefill($this->im, 0, 0, $this->white);
$this->black = ImageColorAllocate($this->im, 0, 0, 0);
$n = count($this->data);
for ($i = 0; $i < $n; $i++) {
$this->colors[$i] = ImageColorAllocate($this->im, $this->data[$i][2], $this->data[$i][3], $this->data[$i][4]);
$this->sum += $this->data[$i][0];
}
$from = 0;
$to = 0;
for ($i = 0; $i < $n; $i++) {
$this->angles[$i] = $this->roundoff($this->data[$i][0] * 360 / doubleval($this->sum));
}
$this->draw_slices($this->center_x, $this->center_y, $this->angles, $this->colors);
}
示例13: ImageCreateFromPNG
<?php
// Rectangle Version
$filename = __DIR__ . '/php.png';
// Thumbnail Dimentions
$w = 50;
$h = 20;
// Images
$original = ImageCreateFromPNG($filename);
$thumbnail = ImageCreateTrueColor($w, $h);
// Preserve Transparency
ImageColorTransparent($thumbnail, ImageColorAllocateAlpha($thumbnail, 0, 0, 0, 127));
ImageAlphaBlending($thumbnail, false);
ImageSaveAlpha($thumbnail, true);
// Scale & Copy
$x = ImageSX($original);
$y = ImageSY($original);
$scale = min($x / $w, $y / $h);
ImageCopyResampled($thumbnail, $original, 0, 0, ($x - $w * $scale) / 2, ($y - $h * $scale) / 2, $w, $h, $w * $scale, $h * $scale);
// Send
header('Content-type: image/png');
ImagePNG($thumbnail);
ImageDestroy($original);
ImageDestroy($thumbnail);
示例14: ImageTTFText
for ($i = 1; $i <= 3; $i++) {
if (isset($profs[$i - 1]) > 0) {
$prof = $profs[$i - 1];
$name = $prof['name'];
$v = $prof['value'];
$txt = "{$v} {$name}";
$textLeft += 100;
ImageTTFText($img, 8, 0, $textLeft, 90, $textcolor, $plainFont, win2uni($txt));
}
}
$lineWidth = 495 - $new_width - 45 - 45;
$midWidth = $lineWidth;
$y = 43;
ImageLine($img, $new_width + 45, $y, 445, $y, $textcolor);
for ($i = 0; $i < 40; $i++) {
$c = ImageColorAllocateAlpha($img, $text_r, $text_g, $text_b, floor(87 / 40 * $i) + 40);
ImageLine($img, $new_width + 45 + 1 - $i, $y, $new_width + 45 - $i, $y, $c);
ImageLine($img, 445 + $i, $y, 446 + $i, $y, $c);
ImageColorDeallocate($img, $c);
}
ImageTTFText($img, 10, 0, $new_width + 5, 59, $textcolor, $mainFont, win2uni($row['race']) . " " . win2uni($row['clevel']) . " ур. - WWW.RPG.SU");
if ($row['clan_id'] > 0) {
$clan_name = mysql_result(myquery("SELECT nazv FROM game_clans WHERE clan_id=" . $row['clan_id'] . ""), 0, 0);
ImageTTFText($img, 9, 0, $new_width + 5, 72, $textcolor, $mainFont, "<" . $clan_name . "> " . "");
} else {
ImageTTFText($img, 9, 0, $new_width + 5, 72, $textcolor, $mainFont, "Средиземье :: Эпоха Сражений" . "");
}
ImageTTFText($img, 8, 0, $new_width + 25, 10, $textcolor, $mainFont, $reason);
for ($n = 1; $n <= 6; $n++) {
$w = $sta[$n];
$texu = "{$w}";
示例15: makeBox
/**
* Implements the "BOX" GIFBUILDER object
*
* @param resource $im GDlib image pointer
* @param array $conf TypoScript array with configuration for the GIFBUILDER object.
* @param array $workArea The current working area coordinates.
* @return void
* @see \TYPO3\CMS\Frontend\Imaging\GifBuilder::make()
*/
public function makeBox(&$im, $conf, $workArea)
{
$cords = GeneralUtility::intExplode(',', $conf['dimensions'] . ',,,');
$conf['offset'] = $cords[0] . ',' . $cords[1];
$cords = $this->objPosition($conf, $workArea, array($cords[2], $cords[3]));
$cols = $this->convertColor($conf['color']);
$opacity = 0;
if (isset($conf['opacity'])) {
// conversion:
// PHP 0 = opaque, 127 = transparent
// TYPO3 100 = opaque, 0 = transparent
$opacity = MathUtility::forceIntegerInRange((int) $conf['opacity'], 1, 100, 1);
$opacity = abs($opacity - 100);
$opacity = round(127 * $opacity / 100);
}
$tmpColor = ImageColorAllocateAlpha($im, $cols[0], $cols[1], $cols[2], $opacity);
imagefilledrectangle($im, $cords[0], $cords[1], $cords[0] + $cords[2] - 1, $cords[1] + $cords[3] - 1, $tmpColor);
}