• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

PHP imagecolorallocatealpha函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了PHP中imagecolorallocatealpha函数的典型用法代码示例。如果您正苦于以下问题:PHP imagecolorallocatealpha函数的具体用法?PHP imagecolorallocatealpha怎么用?PHP imagecolorallocatealpha使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。



在下文中一共展示了imagecolorallocatealpha函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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;
}
开发者ID:Kufirc,项目名称:Gazelle,代码行数:30,代码来源:index.php


示例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));
         }
     }
 }
开发者ID:rsids,项目名称:bright_api,代码行数:29,代码来源:ImageUtils.php


示例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);
         }
     }
 }
开发者ID:knigherrant,项目名称:decopatio,代码行数:42,代码来源:threshold.php


示例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;
}
开发者ID:mcenderdragon,项目名称:Icon-Craft,代码行数:26,代码来源:block_renderer.php


示例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();
 }
开发者ID:shads196770,项目名称:cbox-theme,代码行数:37,代码来源:wpthumb.background-fill.php


示例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);
                 }
             }
         }
     }
 }
开发者ID:feeel1,项目名称:akina,代码行数:27,代码来源:Output.php


示例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;
 }
开发者ID:EdgarPost,项目名称:image,代码行数:41,代码来源:ResizeCommand.php


示例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);
 }
开发者ID:lenlyle1,项目名称:lightupdating,代码行数:26,代码来源:Resize.php


示例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();
 }
开发者ID:phpoffice,项目名称:phppowerpoint,代码行数:30,代码来源:ThumbnailsThumbnail.php


示例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);
}
开发者ID:qichangjun,项目名称:HTMLLearn,代码行数:34,代码来源:upload.php


示例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;
 }
开发者ID:q0821,项目名称:esportshop,代码行数:30,代码来源:qrcode.php


示例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;
 }
开发者ID:BGCX262,项目名称:zym-svn-to-git,代码行数:13,代码来源:DrawText.php


示例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;
     }
 }
开发者ID:appsco,项目名称:component-share,代码行数:32,代码来源:ImageResizer.php


示例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;
 }
开发者ID:hbarcelos,项目名称:gd-wrapper,代码行数:11,代码来源:TransparentResource.php


示例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;
 }
开发者ID:laiello,项目名称:hecart,代码行数:29,代码来源:image.php


示例16: createCaptcha

 public function createCaptcha()
 {
     $captcha = '';
     $symbol = '0';
     $width = 420;
     $height = 70;
     $font = 'fonts/bellb.ttf';
     $fontsize = 20;
     $captchaLength = rand(1, 1);
     $im = imagecreatetruecolor($width, $height);
     $bg = imagecolorallocatealpha($im, 0, 0, 0, 127);
     imagefill($im, 0, 0, $bg);
     for ($i = 0; $i < $captchaLength; $i++) {
         $captcha .= $symbol[rand(0, strlen($symbol) - 1)];
         $x = ($width - 20) / $captchaLength * $i + 10;
         $x = rand($x, $x + 4);
         $y = $height - ($height - $fontsize) / 2;
         $curcolor = imagecolorallocate($im, rand(0, 100), rand(0, 100), rand(0, 100));
         $angle = rand(-25, 25);
         imagettftext($im, $fontsize, $angle, $x, $y, $curcolor, $font, $captcha[$i]);
     }
     session_start();
     $_SESSION['captcha'] = $captcha;
     header('Content-type: image/png');
     imagepng($im);
     imagedestroy($im);
 }
开发者ID:Arxemond777,项目名称:News,代码行数:27,代码来源:captcha.php


示例17: add_image

 /**
  * Add an image to the generator.
  *
  * This function adds a source image to the generator. It serves two main purposes: add a source image if one was
  * not supplied to the constructor and to add additional source images so that different images can be supplied for
  * different sized images in the resulting ICO file. For instance, a small source image can be used for the small
  * resolutions while a larger source image can be used for large resolutions.
  *
  * @param string $file Path to the source image file.
  * @param array $sizes Optional. An array of sizes (each size is an array with a width and height) that the source image should be rendered at in the generated ICO file. If sizes are not supplied, the size of the source image will be used.
  * @return boolean true on success and false on failure.
  */
 public function add_image($file, $sizes = array())
 {
     if (!$this->_has_requirements) {
         return false;
     }
     if (false === ($im = $this->_load_image_file($file))) {
         return false;
     }
     if (empty($sizes)) {
         $sizes = array(imagesx($im), imagesy($im));
     }
     // If just a single size was passed, put it in array.
     if (!is_array($sizes[0])) {
         $sizes = array($sizes);
     }
     foreach ((array) $sizes as $size) {
         list($width, $height) = $size;
         $new_im = imagecreatetruecolor($width, $height);
         imagecolortransparent($new_im, imagecolorallocatealpha($new_im, 0, 0, 0, 127));
         imagealphablending($new_im, false);
         imagesavealpha($new_im, true);
         $source_width = imagesx($im);
         $source_height = imagesy($im);
         if (false === imagecopyresampled($new_im, $im, 0, 0, 0, 0, $width, $height, $source_width, $source_height)) {
             continue;
         }
         $this->_add_image_data($new_im);
     }
     return true;
 }
开发者ID:elvyrra,项目名称:hawk,代码行数:42,代码来源:PHPICO.php


示例18: execute

 /**
  * Reduces colors of a given image
  *
  * @param  \Intervention\Image\Image $image
  * @return boolean
  */
 public function execute($image)
 {
     $count = $this->argument(0)->value();
     $matte = $this->argument(1)->value();
     // get current image size
     $size = $image->getSize();
     // create empty canvas
     $resource = imagecreatetruecolor($size->width, $size->height);
     // define matte
     if (is_null($matte)) {
         $matte = imagecolorallocatealpha($resource, 255, 255, 255, 127);
     } else {
         $matte = $image->getDriver()->parseColor($matte)->getInt();
     }
     // fill with matte and copy original image
     imagefill($resource, 0, 0, $matte);
     // set transparency
     imagecolortransparent($resource, $matte);
     // copy original image
     imagecopy($resource, $image->getCore(), 0, 0, 0, 0, $size->width, $size->height);
     if (is_numeric($count) && $count <= 256) {
         // decrease colors
         imagetruecolortopalette($resource, true, $count);
     }
     // set new resource
     $image->setCore($resource);
     return true;
 }
开发者ID:shubhomoy,项目名称:evolve,代码行数:34,代码来源:LimitColorsCommand.php


示例19: _createImage

 /**
  * 创建图像
  *
  * @return resource
  */
 protected function _createImage()
 {
     if (!is_resource($this->_image)) {
         extract($this->_options);
         //解出参数到变量
         $this->_image = imagecreatetruecolor($width, $height);
         $color1 = imagecolorallocate($this->_image, mt_rand(200, 255), mt_rand(200, 255), mt_rand(150, 255));
         $color2 = imagecolorallocate($this->_image, mt_rand(200, 255), mt_rand(200, 255), mt_rand(150, 255));
         $color1 = imagecolorsforindex($this->_image, $color1);
         $color2 = imagecolorsforindex($this->_image, $color2);
         $steps = $width;
         $r1 = ($color1['red'] - $color2['red']) / $steps;
         $g1 = ($color1['green'] - $color2['green']) / $steps;
         $b1 = ($color1['blue'] - $color2['blue']) / $steps;
         $x1 = 0;
         $y1 =& $i;
         $x2 = $width;
         $y2 =& $i;
         for ($i = 0; $i <= $steps; $i++) {
             $r2 = $color1['red'] - floor($i * $r1);
             $g2 = $color1['green'] - floor($i * $g1);
             $b2 = $color1['blue'] - floor($i * $b1);
             $color = imagecolorallocate($this->_image, $r2, $g2, $b2);
             imageline($this->_image, $x1, $y1, $x2, $y2, $color);
         }
         for ($i = 0, $count = mt_rand(10, 20); $i < $count; $i++) {
             $color = imagecolorallocatealpha($this->_image, mt_rand(20, 255), mt_rand(20, 255), mt_rand(100, 255), mt_rand(80, 120));
             imageline($this->_image, mt_rand(0, $width), 0, mt_rand(0, $width), $height, $color);
         }
     }
     return $this->_image;
 }
开发者ID:BGCX261,项目名称:zhongyycode-svn-to-git,代码行数:37,代码来源:Basic.php


示例20: applyFilter

 /**
  * Applies filter effects to the given image
  *
  * @param Image\Image $image The image to filter.
  *
  * @return Image\Image The filtered image.
  *
  * @throws FilterException if the image filter algorithm fails.
  */
 public function applyFilter(Image\Image $image)
 {
     if ($this->level <= 0) {
         $gd = $image->getCore();
         $width = imagesx($gd);
         $height = imagesy($gd);
         for ($x = 0; $x < $width; ++$x) {
             for ($y = 0; $y < $height; ++$y) {
                 $rgba = imagecolorsforindex($gd, imagecolorat($gd, $x, $y));
                 $r = $rgba['red'];
                 $g = $rgba['green'];
                 $b = $rgba['blue'];
                 $a = $rgba['alpha'];
                 $level = $this->level * -1;
                 $max = max($r, $g, $b);
                 $avg = ($r + $g + $b) / 3;
                 $amt = abs($max - $avg) * 2 / 255 * $level / 100;
                 if ($r !== $max) {
                     $r += ($max - $r) * $amt;
                 }
                 if ($g !== $max) {
                     $g += ($max - $g) * $amt;
                 }
                 if ($b !== $max) {
                     $b += ($max - $b) * $amt;
                 }
                 imagesetpixel($gd, $x, $y, imagecolorallocatealpha($gd, $r, $g, $b, $a));
             }
         }
         $image->setCore($gd);
     } else {
         $image->filter(new SaturateFilter($this->level));
     }
     return $image;
 }
开发者ID:BitmanNL,项目名称:traffictower-cms,代码行数:44,代码来源:VibranceFilter.php



注:本文中的imagecolorallocatealpha函数示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
PHP imagecolorat函数代码示例发布时间:2022-05-15
下一篇:
PHP imagecolorallocate函数代码示例发布时间:2022-05-15
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap