本文整理汇总了PHP中imagecolorallocatealpha函数的典型用法代码示例。如果您正苦于以下问题:PHP imagecolorallocatealpha函数的具体用法?PHP imagecolorallocatealpha怎么用?PHP imagecolorallocatealpha使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了imagecolorallocatealpha函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: make_captcha_img
function make_captcha_img()
{
global $CaptchaBGs;
$Length = 6;
$ImageHeight = 75;
$ImageWidth = 300;
$Chars = 'abcdefghjkmprstuvwxyzABCDEFGHJKLMPQRSTUVWXY23456789';
$CaptchaString = '';
for ($i = 0; $i < $Length; $i++) {
$CaptchaString .= $Chars[mt_rand(0, strlen($Chars) - 1)];
}
for ($x = 0; $x < $Length; $x++) {
$FontDisplay[$x]['size'] = mt_rand(24, 32);
$FontDisplay[$x]['top'] = mt_rand($FontDisplay[$x]['size'] + 5, $ImageHeight - $FontDisplay[$x]['size'] / 2);
$FontDisplay[$x]['angle'] = mt_rand(-30, 30);
$FontDisplay[$x]['font'] = get_font();
}
$Img = imagecreatetruecolor($ImageWidth, $ImageHeight);
$BGImg = imagecreatefrompng(SERVER_ROOT . '/captcha/' . $CaptchaBGs[mt_rand(0, count($CaptchaBGs) - 1)]);
imagecopymerge($Img, $BGImg, 0, 0, 0, 0, 300, 75, 50);
$ForeColor = imagecolorallocatealpha($Img, 255, 255, 255, 65);
for ($i = 0; $i < strlen($CaptchaString); $i++) {
$CharX = $ImageWidth / $Length * ($i + 1) - $ImageWidth / $Length * 0.75;
imagettftext($Img, $FontDisplay[$i]['size'], $FontDisplay[$i]['angle'], $CharX, $FontDisplay[$i]['top'], $ForeColor, $FontDisplay[$i]['font'], $CaptchaString[$i]);
}
header('Content-type: image/png');
imagepng($Img);
imagedestroy($Img);
return $CaptchaString;
}
示例2: ImageHue
public static function ImageHue(&$image, $hue, $saturation)
{
$width = imagesx($image);
$height = imagesy($image);
for ($x = 0; $x < $width; $x++) {
for ($y = 0; $y < $height; $y++) {
$rgb = imagecolorat($image, $x, $y);
$r = $rgb >> 16 & 0xff;
$g = $rgb >> 8 & 0xff;
$b = $rgb & 0xff;
$alpha = ($rgb & 0x7f000000) >> 24;
$hsl = ColorUtils::rgb2hsl(array('r' => $r, 'g' => $g, 'b' => $b));
$h = $hsl['h'] / 360;
$s = $hsl['s'] / 100;
$h += $hue / 360;
$s += $saturation / 100;
if ($h > 1) {
$h--;
}
if ($s > 1) {
$s--;
}
$hsl['h'] = $h * 360;
$hsl['s'] = $s * 100;
$rgb = ColorUtils::hsl2rgb($hsl);
imagesetpixel($image, $x, $y, imagecolorallocatealpha($image, $rgb['r'], $rgb['g'], $rgb['b'], $alpha));
}
}
}
示例3: execute
/**
* Method to apply a filter to an image resource.
*
* @param array $options An array of options for the filter.
*
* @return void
*
* @throws InvalidArgumentException
* @throws RuntimeException
*/
public function execute(array $options = array())
{
// Verify that image filter support for PHP is available.
if (!function_exists('imagefilter')) {
throw new RuntimeException('The imagefilter function for PHP is not available.');
}
if (empty($options)) {
throw new InvalidArgumentException('No valid amount was given. Expected float.');
}
$value = (int) array_shift($options);
if ($value == 0) {
$value = 128;
}
$width = imagesx($this->handle);
$height = imagesy($this->handle);
for ($x = 0; $x < $width; ++$x) {
for ($y = 0; $y < $height; ++$y) {
$index = imagecolorat($this->handle, $x, $y);
$rgb = imagecolorsforindex($this->handle, $index);
$r = $rgb['red'];
$g = $rgb['green'];
$b = $rgb['blue'];
$a = $rgb['alpha'];
$v = round(($r + $g + $b) / 3) >= $value ? 255 : 0;
$color = imagecolorallocatealpha($this->handle, $v, $v, $v, $a);
if ($color === false) {
$color = imagecolorclosestalpha($this->handle, $v, $v, $v, $a);
}
imagesetpixel($this->handle, $x, $y, $color);
}
}
}
示例4: render_block
function render_block($left_side, $top_side, $right_side)
{
global $size;
$size = 2048;
$x1 = (2 - sqrt(3)) * 0.25 * $size;
$x2 = 0.5 * $size;
$x3 = (2 + sqrt(3)) * 0.25 * $size;
$y1 = 0;
$y2 = 0.25 * $size;
$y3 = 0.5 * $size;
$y4 = 0.75 * $size;
$y5 = $size;
$first_poligon = array($x1, $y2, $x2, $y3, $x2, $y5, $x1, $y4);
$second_poligon = array($x1, $y2, $x2, $y1, $x3, $y2, $x2, $y3);
$third_poligon = array($x2, $y3, $x3, $y2, $x3, $y4, $x2, $y5);
$im = imagecreatetruecolor($size, $size);
// Transparentbackground
imagealphablending($im, true);
imagesavealpha($im, true);
$trans = imagecolorallocatealpha($im, 0, 0, 0, 127);
imagefill($im, 0, 0, $trans);
imagetranslatedtexture($im, $first_poligon, imagelight(load_png($left_side), 96));
imagetranslatedtexture($im, $second_poligon, load_png($top_side));
imagetranslatedtexture($im, $third_poligon, imagelight(load_png($right_side), 64));
return $im;
}
示例5: fill_color
/**
* Background fill an image using the provided color
*
* @param int $width The desired width of the new image
* @param int $height The desired height of the new image
* @param Array the desired pad colors in RGB format, array should be array( 'top' => '', 'right' => '', 'bottom' => '', 'left' => '' );
*/
private function fill_color(array $colors)
{
$current_size = $this->editor->get_size();
$size = array('width' => $this->args['width'], 'height' => $this->args['height']);
$offsetLeft = ($size['width'] - $current_size['width']) / 2;
$offsetTop = ($size['height'] - $current_size['height']) / 2;
$new_image = imagecreatetruecolor($size['width'], $size['height']);
// This is needed to support alpha
imagesavealpha($new_image, true);
imagealphablending($new_image, false);
// Check if we are padding vertically or horizontally
if ($current_size['width'] != $size['width']) {
$colorToPaint = imagecolorallocatealpha($new_image, substr($colors['left'], 0, 3), substr($colors['left'], 3, 3), substr($colors['left'], 6, 3), substr($colors['left'], 9, 3));
// Fill left color
imagefilledrectangle($new_image, 0, 0, $offsetLeft + 5, $size['height'], $colorToPaint);
$colorToPaint = imagecolorallocatealpha($new_image, substr($colors['right'], 0, 3), substr($colors['right'], 3, 3), substr($colors['right'], 6, 3), substr($colors['left'], 9, 3));
// Fill right color
imagefilledrectangle($new_image, $offsetLeft + $current_size['width'] - 5, 0, $size['width'], $size['height'], $colorToPaint);
} elseif ($current_size['height'] != $size['height']) {
$colorToPaint = imagecolorallocatealpha($new_image, substr($colors['top'], 0, 3), substr($colors['top'], 3, 3), substr($colors['top'], 6, 3), substr($colors['left'], 9, 3));
// Fill top color
imagefilledrectangle($new_image, 0, 0, $size['width'], $offsetTop + 5, $colorToPaint);
$colorToPaint = imagecolorallocatealpha($new_image, substr($colors['bottom'], 0, 3), substr($colors['bottom'], 3, 3), substr($colors['bottom'], 6, 3), substr($colors['left'], 9, 3));
// Fill bottom color
imagefilledrectangle($new_image, 0, $offsetTop - 5 + $current_size['height'], $size['width'], $size['height'], $colorToPaint);
}
imagecopy($new_image, $this->editor->get_image(), $offsetLeft, $offsetTop, 0, 0, $current_size['width'], $current_size['height']);
$this->editor->update_image($new_image);
$this->editor->update_size();
}
示例6: setResource
protected function setResource()
{
$this->resource = imagecreatetruecolor($this->background->width, $this->background->height);
if (isset($this->fill) === true) {
$backgroundindex = imagecolorallocate($this->resource, $this->fill['red'], $this->fill['green'], $this->fill['blue']);
imagefill($this->resource, 0, 0, $backgroundindex);
} else {
if ($this->format === 'gif') {
$backgroundindex = imagecolorallocatealpha($this->resource, 255, 255, 255, 127);
imagefill($this->resource, 0, 0, $backgroundindex);
imagecolortransparent($this->resource, $backgroundindex);
} else {
if ($this->format === 'jpeg') {
$backgroundindex = imagecolorallocate($this->resource, 255, 255, 255);
imagefill($this->resource, 0, 0, $backgroundindex);
} else {
if ($this->format === 'png') {
imagealphablending($this->resource, false);
imagesavealpha($this->resource, true);
$backgroundindex = imagecolorallocatealpha($this->resource, 255, 255, 255, 127);
imagefill($this->resource, 0, 0, $backgroundindex);
imagealphablending($this->resource, true);
}
}
}
}
}
示例7: modify
/**
* Wrapper function for 'imagecopyresampled'
*
* @param Image $image
* @param integer $dst_x
* @param integer $dst_y
* @param integer $src_x
* @param integer $src_y
* @param integer $dst_w
* @param integer $dst_h
* @param integer $src_w
* @param integer $src_h
* @return boolean
*/
protected function modify($image, $dst_x, $dst_y, $src_x, $src_y, $dst_w, $dst_h, $src_w, $src_h)
{
foreach ($image as $frame) {
// create new image
$modified = imagecreatetruecolor($dst_w, $dst_h);
// get current image
$resource = $frame->getCore();
// preserve transparency
$transIndex = imagecolortransparent($resource);
if ($transIndex != -1) {
$rgba = imagecolorsforindex($modified, $transIndex);
$transColor = imagecolorallocatealpha($modified, $rgba['red'], $rgba['green'], $rgba['blue'], 127);
imagefill($modified, 0, 0, $transColor);
imagecolortransparent($modified, $transColor);
} else {
imagealphablending($modified, false);
imagesavealpha($modified, true);
}
// copy content from resource
imagecopyresampled($modified, $resource, $dst_x, $dst_y, $src_x, $src_y, $dst_w, $dst_h, $src_w, $src_h);
// free memory of old core
imagedestroy($resource);
// set new content as recource
$frame->setCore($modified);
}
return true;
}
示例8: Resize
public function Resize($image, $newWidth, $targetName)
{
if (!file_exists(PUBLIC_ROOT . $image)) {
$image = '/assets/images/not-found.gif';
}
$imgInfo = getimagesize(PUBLIC_ROOT . $image);
$oldWidth = $imgInfo[0];
$oldHeight = $imgInfo[1];
$changeRatio = $oldWidth / $newWidth;
$newHeight = round($oldHeight / $changeRatio);
$newImage = imagecreatetruecolor($newWidth, $newHeight);
$source = $this->load(PUBLIC_ROOT . $image);
if ($this->imageType == IMAGETYPE_PNG) {
imagealphablending($newImage, false);
imagesavealpha($newImage, true);
$transparent = imagecolorallocatealpha($newImage, 255, 255, 255, 127);
imagefilledrectangle($newImage, 0, 0, $newWidth, $newHeight, $transparent);
}
imagecopyresampled($newImage, $this->image, 0, 0, 0, 0, $newWidth, $newHeight, $oldWidth, $oldHeight);
header('Content-Type: image/jpeg');
imagejpeg($newImage, $targetName, 100);
Debugger::debug($targetName, 'TARGET');
//$this->save($targetName);
$this->image = $newImage;
imagedestroy($newImage);
}
示例9: render
/**
* @return ZipInterface
*/
public function render()
{
$pathThumbnail = $this->getPresentation()->getPresentationProperties()->getThumbnailPath();
if ($pathThumbnail) {
// Size : 128x128 pixel
// PNG : 8bit, non-interlaced with full alpha transparency
$gdImage = imagecreatefromstring(file_get_contents($pathThumbnail));
if ($gdImage) {
list($width, $height) = getimagesize($pathThumbnail);
$gdRender = imagecreatetruecolor(128, 128);
$colorBgAlpha = imagecolorallocatealpha($gdRender, 0, 0, 0, 127);
imagecolortransparent($gdRender, $colorBgAlpha);
imagefill($gdRender, 0, 0, $colorBgAlpha);
imagecopyresampled($gdRender, $gdImage, 0, 0, 0, 0, 128, 128, $width, $height);
imagetruecolortopalette($gdRender, false, 255);
imagesavealpha($gdRender, true);
ob_start();
imagepng($gdRender);
$imageContents = ob_get_contents();
ob_end_clean();
imagedestroy($gdRender);
imagedestroy($gdImage);
$this->getZip()->addFromString('Thumbnails/thumbnail.png', $imageContents);
}
}
return $this->getZip();
}
示例10: createImage
function createImage($name, $filename, $new_w, $new_h)
{
$system2 = explode('.', strtolower(basename($filename)));
$system2[1] = $system2[1];
$src_img = imagecreatefromstring(readFileData($name));
$old_w = imageSX($src_img);
$old_h = imageSY($src_img);
$thumb_w = $new_w;
$thumb_h = $new_h;
if ($new_w > $old_w) {
$thumb_w = $old_w;
$thumb_h = $thumb_w / $old_w * $old_h;
} else {
$thumb_w = $new_w;
$thumb_h = $thumb_w / $old_w * $old_h;
}
if ($thumb_h > $new_h) {
$thumb_h = $new_h;
$thumb_w = $thumb_h / $old_h * $old_w;
}
$dst_img = ImageCreateTrueColor($thumb_w, $thumb_h);
imagealphablending($dst_img, false);
imagesavealpha($dst_img, true);
$transparent = imagecolorallocatealpha($dst_img, 255, 255, 255, 127);
imagefilledrectangle($dst_img, 0, 0, $thumb_w, $thumb_h, $transparent);
imagecopyresampled($dst_img, $src_img, 0, 0, 0, 0, $thumb_w, $thumb_h, $old_w, $old_h);
if (preg_match("/png/", $system2[1])) {
imagepng($dst_img, $filename);
} else {
imagejpeg($dst_img, $filename, 90);
}
imagedestroy($dst_img);
imagedestroy($src_img);
}
示例11: getImage
public function getImage($data)
{
$pngData = $this->encode($data);
if ($pngData == null) {
return null;
}
$h = count($pngData);
$w = strlen($pngData[0]);
$imgW = $w + 2 * $this->outerFrame;
$imgH = $h + 2 * $this->outerFrame;
$qrcode_image = imagecreatetruecolor($imgW, $imgH);
imagealphablending($qrcode_image, false);
$qrBackColor = imagecolorallocatealpha($qrcode_image, 255, 255, 255, 127);
imagefill($qrcode_image, 0, 0, $qrBackColor);
imagesavealpha($qrcode_image, true);
if (!empty($this->fgcolor) && (substr($this->fgcolor, 0, 1) == '#' && strlen(trim($this->fgcolor)) == 7 || strlen(trim($this->fgcolor)) == 6)) {
$rgb = str_split(ltrim($this->fgcolor, '#'), 2);
$qrColor = imagecolorallocatealpha($qrcode_image, hexdec($rgb[0]), hexdec($rgb[1]), hexdec($rgb[2]), 0);
} else {
$qrColor = imagecolorallocatealpha($qrcode_image, 0, 0, 0, 0);
}
for ($y = 0; $y < $h; $y++) {
for ($x = 0; $x < $w; $x++) {
if ($pngData[$y][$x] == '1') {
imagesetpixel($qrcode_image, $x + $this->outerFrame, $y + $this->outerFrame, $qrColor);
}
}
}
return $qrcode_image;
}
示例12: perform
/**
* Draws some text on the handle
*
* @param GD-object $handle The handle on which the ellipse is drawn
* @param Zend_Image_Action_DrawText $textObject The object that with all info
*/
public function perform($handle, Zend_Image_Action_DrawText $textObject)
{
// As of ZF2.0 / PHP5.3, this can be made static.
$color = Zend_Image_Color::calculateHex($textObject->getColor());
$colorAlphaAlloc = imagecolorallocatealpha($handle, $color['red'], $color['green'], $color['blue'], 127 - $textObject->getAlpha());
return $handle;
}
示例13: scale
/**
* @param int $width Target width
* @param int $height Target height
* @param bool $toFit If true, image fill fit to given dimensions, if false, it will cover them
* @param bool $force If true, image will be resized even if target dimensions are larger than original
*/
protected function scale($width, $height, $toFit, $force)
{
if (null === $this->_image) {
return;
}
$rawWidth = $this->_getWidth();
$rawHeight = $this->_getHeight();
$widthOver = $rawWidth / $width;
$heightOver = $rawHeight / $height;
if ($toFit) {
$scalingFactor = max($widthOver, $heightOver);
} else {
$scalingFactor = min($widthOver, $heightOver);
}
if ($scalingFactor > 1 || $force) {
$destWidth = $rawWidth / $scalingFactor;
$destHeight = $rawHeight / $scalingFactor;
$destImage = imagecreatetruecolor($destWidth, $destHeight);
imagealphablending($destImage, false);
imagesavealpha($destImage, true);
$transparent = imagecolorallocatealpha($destImage, 255, 255, 255, 127);
imagefill($destImage, 0, 0, $transparent);
imagecopyresampled($destImage, $this->_image, 0, 0, 0, 0, $destWidth, $destHeight, $rawWidth, $rawHeight);
$this->_image = $destImage;
}
}
示例14: createRaw
/**
* {@inherit-doc}
* @see Hbarcelos\GdWrapper\Resource\EmptyResource::createRaw()
*/
protected function createRaw($width, $height)
{
$raw = imagecreatetruecolor($width, $height);
$transparent = imagecolorallocatealpha($raw, 255, 255, 255, 127);
imagefilledrectangle($raw, 0, 0, $width, $height, $transparent);
return $raw;
}
示例15: resize
public function resize($width = 0, $height = 0)
{
if (!$this->info['width'] || !$this->info['height']) {
return;
}
$scale = min($width / $this->info['width'], $height / $this->info['height']);
if ($scale == 1 && $this->info['mime'] != 'image/png') {
return;
}
$new_width = (int) ($this->info['width'] * $scale);
$new_height = (int) ($this->info['height'] * $scale);
$xpos = (int) (($width - $new_width) / 2);
$ypos = (int) (($height - $new_height) / 2);
$image_old = $this->image;
$this->image = imagecreatetruecolor($width, $height);
if (isset($this->info['mime']) && $this->info['mime'] == 'image/png') {
imagealphablending($this->image, false);
imagesavealpha($this->image, true);
$background = imagecolorallocatealpha($this->image, 255, 255, 255, 127);
imagecolortransparent($this->image, $background);
} else {
$background = imagecolorallocate($this->image, 255, 255, 255);
}
imagefilledrectangle($this->image, 0, 0, $width, $height, $background);
imagecopyresampled($this->image, $image_old, $xpos, $ypos, 0, 0, $new_width, $new_height, $this->info['width'], $this->info['height']);
imagedestroy($image_old);
$this->info['width'] = $width;
$this->info['height'] = $height;
}