当前位置: 首页>>代码示例>>PHP>>正文


PHP imagesavealpha函数代码示例

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


在下文中一共展示了imagesavealpha函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: load

 static function load($filename)
 {
     $info = getimagesize($filename);
     list($width, $height) = $info;
     if (!$width || !$height) {
         return null;
     }
     $image = null;
     switch ($info['mime']) {
         case 'image/gif':
             $image = imagecreatefromgif($filename);
             break;
         case 'image/jpeg':
             $image = imagecreatefromjpeg($filename);
             break;
         case 'image/png':
             $image = imagecreatetruecolor($width, $height);
             $white = imagecolorallocate($image, 255, 255, 255);
             imagefill($image, 0, 0, $white);
             $png = imagecreatefrompng($filename);
             imagealphablending($png, true);
             imagesavealpha($png, true);
             imagecopy($image, $png, 0, 0, 0, 0, $width, $height);
             imagedestroy($png);
             break;
     }
     if ($image) {
         return new image($image, $width, $height);
     } else {
         return null;
     }
 }
开发者ID:nyan-cat,项目名称:easyweb,代码行数:32,代码来源:image.php

示例2: getAvatar

 public function getAvatar($string, $widthHeight = 12, $theme = 'default')
 {
     $widthHeight = max($widthHeight, 12);
     $md5 = md5($string);
     $fileName = _TMP_DIR_ . '/' . $md5 . '.png';
     if ($this->tmpFileExists($fileName)) {
         return $fileName;
     }
     // Create seed.
     $seed = intval(substr($md5, 0, 6), 16);
     mt_srand($seed);
     $body = array('legs' => mt_rand(0, count($this->availableParts[$theme]['legs']) - 1), 'hair' => mt_rand(0, count($this->availableParts[$theme]['hair']) - 1), 'arms' => mt_rand(0, count($this->availableParts[$theme]['arms']) - 1), 'body' => mt_rand(0, count($this->availableParts[$theme]['body']) - 1), 'eyes' => mt_rand(0, count($this->availableParts[$theme]['eyes']) - 1), 'mouth' => mt_rand(0, count($this->availableParts[$theme]['mouth']) - 1));
     // Avatar random parts.
     $parts = array('legs' => $this->availableParts[$theme]['legs'][$body['legs']], 'hair' => $this->availableParts[$theme]['hair'][$body['hair']], 'arms' => $this->availableParts[$theme]['arms'][$body['arms']], 'body' => $this->availableParts[$theme]['body'][$body['body']], 'eyes' => $this->availableParts[$theme]['eyes'][$body['eyes']], 'mouth' => $this->availableParts[$theme]['mouth'][$body['mouth']]);
     $avatar = imagecreate($widthHeight, $widthHeight);
     imagesavealpha($avatar, true);
     imagealphablending($avatar, false);
     $background = imagecolorallocate($avatar, 0, 0, 0);
     $line_colour = imagecolorallocate($avatar, mt_rand(0, 200) + 55, mt_rand(0, 200) + 55, mt_rand(0, 200) + 55);
     imagecolortransparent($avatar, $background);
     imagefilledrectangle($avatar, 0, 0, $widthHeight, $widthHeight, $background);
     // Fill avatar with random parts.
     foreach ($parts as &$part) {
         $this->drawPart($part, $avatar, $widthHeight, $line_colour, $background);
     }
     imagepng($avatar, $fileName);
     imagecolordeallocate($avatar, $line_colour);
     imagecolordeallocate($avatar, $background);
     imagedestroy($avatar);
     return $fileName;
 }
开发者ID:recallfx,项目名称:monsterid.php,代码行数:31,代码来源:MonsterId.php

示例3: render

 /**
  * @param Frame $frame
  * @param $index
  * @return resource
  */
 protected function render(Frame $frame, $index)
 {
     if ($index == 0) {
         $screenSize = $this->decoder->getScreenSize();
         $im = imagecreatetruecolor($screenSize->getWidth(), $screenSize->getHeight());
         imagealphablending($im, false);
         imagesavealpha($im, true);
         $transColor = imagecolortransparent($im, imagecolorallocatealpha($im, 255, 255, 255, 127));
         imagefill($im, 0, 0, $transColor);
         $this->frameCurrent = $im;
         $this->framePrevious = $frame;
         $this->copyFrameToBuffer($frame);
         return $this->frameCurrent;
     }
     imagepalettetotruecolor($this->frameCurrent);
     $disposalMethod = $this->framePrevious->getDisposalMethod();
     if ($disposalMethod === 0 || $disposalMethod === 1) {
         $this->copyFrameToBuffer($frame);
     } elseif ($disposalMethod === 2) {
         $this->restoreToBackground($this->framePrevious, imagecolortransparent($this->frameCurrent));
         $this->copyFrameToBuffer($frame);
     } else {
         throw new \RuntimeException("Disposal method {$disposalMethod} is not implemented.");
     }
     $this->framePrevious = $frame;
     return $this->frameCurrent;
 }
开发者ID:Nasawa,项目名称:regif,代码行数:32,代码来源:Renderer.php

示例4: save

 public function save()
 {
     $maxHeight = 0;
     $width = 0;
     foreach ($this->_segmentsArray as $segment) {
         $maxHeight = max($maxHeight, $segment->height);
         $width += $segment->width;
     }
     // create our canvas
     $img = imagecreatetruecolor($width, $maxHeight);
     $background = imagecolorallocatealpha($img, 255, 255, 255, 127);
     imagefill($img, 0, 0, $background);
     imagealphablending($img, false);
     imagesavealpha($img, true);
     // start placing our images on a single x axis
     $xPos = 0;
     foreach ($this->_segmentsArray as $segment) {
         $tmp = imagecreatefromjpeg($segment->pathToImage);
         imagecopy($img, $tmp, $xPos, 0, 0, 0, $segment->width, $segment->height);
         $xPos += $segment->width;
         imagedestroy($tmp);
     }
     // create our final output image.
     imagepng($img, $this->_saveToPath);
 }
开发者ID:ejacobs,项目名称:css-sprite,代码行数:25,代码来源:CssSprite.php

示例5: embroidery2image

function embroidery2image($embroidery, $scale_post = 1, $scale_pre = false)
{
    // Create image
    $im = imagecreatetruecolor(ceil($embroidery->imageWidth * $scale_post), ceil($embroidery->imageHeight * $scale_post));
    imagesavealpha($im, true);
    imagealphablending($im, false);
    $color = imagecolorallocatealpha($im, 255, 255, 255, 127);
    imagefill($im, 0, 0, $color);
    // Draw stitches
    foreach ($embroidery->blocks as $block) {
        $color = imagecolorallocate($im, $block->color->r, $block->color->g, $block->color->b);
        $x = false;
        foreach ($block->stitches as $stitch) {
            if ($x !== false) {
                imageline($im, ($x - $embroidery->min->x) * $scale_post, ($y - $embroidery->min->y) * $scale_post, ($stitch->x - $embroidery->min->x) * $scale_post, ($stitch->y - $embroidery->min->y) * $scale_post, $color);
            }
            $x = $stitch->x;
            $y = $stitch->y;
        }
    }
    // Scale finished image
    if ($scale_pre) {
        $im2 = imagecreatetruecolor($embroidery->imageWidth * $scale_post * $scale_pre, $embroidery->imageHeight * $scale_post * $scale_pre);
        imagesavealpha($im2, true);
        imagealphablending($im2, false);
        imagecopyresized($im2, $im, 0, 0, 0, 0, $embroidery->imageWidth * $scale_post * $scale_pre, $embroidery->imageHeight * $scale_post * $scale_pre, $embroidery->imageWidth * $scale_post, $embroidery->imageHeight * $scale_post);
        imagedestroy($im);
        $im = $im2;
    }
    return $im;
}
开发者ID:bobosch,项目名称:embroidery,代码行数:31,代码来源:embroidery2image.php

示例6: 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

示例7: image

 private static function image($frame, $pixelPerPoint = 4, $outerFrame = 4)
 {
     $h = count($frame);
     $w = strlen($frame[0]);
     $imgW = $w + 2 * $outerFrame;
     $imgH = $h + 2 * $outerFrame;
     $base_image = imagecreatetruecolor($imgW, $imgH);
     $col[0] = ImageColorAllocate($base_image, 255, 0, 255);
     $col[1] = ImageColorAllocate($base_image, 0, 0, 0);
     imagecolortransparent($base_image, $col[0]);
     imagealphablending($base_image, true);
     imagesavealpha($base_image, true);
     //        imagefill($base_image, 0, 0, $col[0]);
     imagefill($base_image, 0, 0, 0x7fff0000);
     for ($y = 0; $y < $h; $y++) {
         for ($x = 0; $x < $w; $x++) {
             if ($frame[$y][$x] == '1') {
                 ImageSetPixel($base_image, $x + $outerFrame, $y + $outerFrame, $col[1]);
             }
         }
     }
     $target_image = ImageCreate($imgW * $pixelPerPoint, $imgH * $pixelPerPoint);
     ImageCopyResized($target_image, $base_image, 0, 0, 0, 0, $imgW * $pixelPerPoint, $imgH * $pixelPerPoint, $imgW, $imgH);
     ImageDestroy($base_image);
     return $target_image;
 }
开发者ID:aplitax,项目名称:PHPQRCode,代码行数:26,代码来源:QRimage.php

示例8: 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

示例9: run

 public static function run($res, $width = NULL, $height = NULL)
 {
     $dst_w = Image::width($res);
     $dst_h = Image::height($res);
     if (!empty($width) && !empty($height)) {
         $dst_w = $width;
         $dst_h = $height;
     } elseif (empty($height)) {
         $ratio = $dst_h / $dst_w;
         $dst_w = $width;
         $dst_h = round($dst_w * $ratio);
     } elseif (empty($width)) {
         $ratio = $dst_w / $dst_h;
         $dst_h = $height;
         $dst_w = round($dst_h * $ratio);
     }
     $dst = imagecreatetruecolor($dst_w, $dst_h);
     /* making the new image transparent */
     $background = imagecolorallocate($dst, 0, 0, 0);
     ImageColorTransparent($dst, $background);
     // make the new temp image all transparent
     imagealphablending($dst, false);
     imagesavealpha($dst, true);
     imageAntiAlias($dst, true);
     self::__fill($dst);
     imagecopyresampled($dst, $res, 0, 0, 0, 0, $dst_w, $dst_h, Image::width($res), Image::height($res));
     @imagedestroy($res);
     return $dst;
 }
开发者ID:bauhouse,项目名称:sym-barebones,代码行数:29,代码来源:filter.resize.php

示例10: 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

示例11: 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

示例12: 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

示例13: resize

function resize($src,$dst,$dstw,$dsth,$scala,$percorsosave) {

	$src = $percorsosave.$src;
	$dst = $percorsosave.$dst;
	list($width, $height, $type, $attr) = getimagesize($src);
    switch($type){
      case 1:$im = imagecreatefromgif($src);break;
      case 2:$im = imagecreatefromjpeg($src);break;
      case 3:$im = imagecreatefrompng($src);break;
      case 8:$im = imagecreatefromwbmp($src);break;
      default:break;
    }
	If ($dstw == "0" && $dsth == "0") { 
			$dstw = $width;
			$dsth = $height;
	}
	switch($scala){
		//scala in base alla lunghezza
		case 1:
			$dsth=($height*$dstw)/$width;
			break;
		//scala in base all'altezza
		case 2:
			$dstw=($width*$dsth)/$height;
			break;
		default:break;
	};
	$tim = imagecreatetruecolor($dstw,$dsth);	
    imagesavealpha($tim,true);
    imagealphablending($tim,false);
    imagecopyresampled($tim,$im,0,0,0,0,$dstw,$dsth,$width,$height);
    ImageJPEG($tim,$dst,90);
    imagedestroy($tim);
}
开发者ID:arkosoft,项目名称:sitoweb-sadmin,代码行数:34,代码来源:functions.php

示例14: prepare

 public function prepare()
 {
     if (!isset($this->img['src'])) {
         $this->gifsupport = function_exists('imagegif');
         // if mimetype detected and in imagemap -> change format
         if (class_exists("finfo") && ($finfo = new finfo(FILEINFO_MIME_TYPE))) {
             if ($ftype = @$finfo->file($this->img['filepath'])) {
                 if (array_key_exists($ftype, $this->image_mimetype_map)) {
                     $this->img['format'] = $this->image_mimetype_map[$ftype];
                 }
             }
         }
         // ----- detect image format
         if ($this->img['format'] == 'jpg' || $this->img['format'] == 'jpeg') {
             $this->img['format'] = 'jpeg';
             $this->img['src'] = @imagecreatefromjpeg($this->img['filepath']);
         } elseif ($this->img['format'] == 'png') {
             $this->img['src'] = @imagecreatefrompng($this->img['filepath']);
             imagealphablending($this->img['src'], false);
             imagesavealpha($this->img['src'], true);
         } elseif ($this->img['format'] == 'gif') {
             if ($this->gifsupport) {
                 $this->img['src'] = @imagecreatefromgif($this->img['filepath']);
             }
         } elseif ($this->img['format'] == 'wbmp') {
             $this->img['src'] = @imagecreatefromwbmp($this->img['filepath']);
         }
         if (isset($this->img['src'])) {
             $this->refreshDimensions();
         }
     }
 }
开发者ID:Barnhiac,项目名称:MTW_REDAXO,代码行数:32,代码来源:class.rex_image.inc.php

示例15: addAttachments

 public function addAttachments($con)
 {
     $decoded = null;
     if (strpos($this->link, 'http://') === false && strpos($this->link, 'https://') === false) {
         $decoded = base64_decode(preg_replace('#^data:image/\\w+;base64,#i', '', $this->link));
     }
     if ($decoded) {
         $name = $this->message_id . "-" . md5($decoded);
         $filename = __DIR__ . '/../../images/' . $name . '.png';
         if (!file_exists($filename)) {
             $img = imagecreatefromstring($decoded);
             imagealphablending($img, false);
             imagesavealpha($img, true);
             imagepng($img, $filename);
         }
         $this->link = $name . '.png';
     }
     $query = "INSERT INTO attachments VALUES(" . $this->message_id . ", '" . $this->link . "', '" . $this->title . "')";
     if ($con) {
         $res = $con->exec($query);
     } else {
         $res = db::query($query);
     }
     $arr = array('id' => $this->message_id, 'link' => $this->link, 'title' => $this->title);
     return $arr;
 }
开发者ID:artemii235,项目名称:SimpleChat,代码行数:26,代码来源:ModelAttachment.php


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