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


PHP imageSaveAlpha函数代码示例

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


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

示例1: loadImg

 public function loadImg($file)
 {
     if (!file_exists($file)) {
         //echo("File not found in loadImg().");
         return false;
     }
     $this->imageSize = getimagesize($file);
     if (!defined("IMAGETYPE_JPG")) {
         define("IMAGETYPE_JPG", IMAGETYPE_JPEG);
     }
     switch ($this->imageSize[2]) {
         case IMAGETYPE_JPG:
             $this->img = imagecreatefromjpeg($file);
             $this->file = $file;
             return true;
         case IMAGETYPE_PNG:
             $this->img = imagecreatefrompng($file);
             imageAlphaBlending($this->img, false);
             imageSaveAlpha($this->img, true);
             $this->file = $file;
             return true;
         case IMAGETYPE_GIF:
             $this->img = imagecreatefromgif($file);
             $this->file = $file;
             break;
         case IMAGETYPE_BMP:
             $this->img = ImageCreateFromBMP($file);
             $this->file = $file;
         default:
             //coreIMG::trace("Unknown file format in loadImg().");
             return false;
     }
 }
开发者ID:NaveedWebdeveloper,项目名称:Test,代码行数:33,代码来源:class.imageResize.php

示例2: execute

 /**
  * Method to apply a background color to an image resource.
  *
  * @param   array  $options  An array of options for the filter.
  *                           color  Background matte color
  *
  * @return  void
  *
  * @since   3.4
  * @throws  InvalidArgumentException
  * @deprecated  5.0  Use Joomla\Image\Filter\Backgroundfill::execute() instead
  */
 public function execute(array $options = array())
 {
     // Validate that the color value exists and is an integer.
     if (!isset($options['color'])) {
         throw new InvalidArgumentException('No color value was given. Expected string or array.');
     }
     $colorCode = !empty($options['color']) ? $options['color'] : null;
     // Get resource dimensions
     $width = imagesX($this->handle);
     $height = imagesY($this->handle);
     // Sanitize color
     $rgba = $this->sanitizeColor($colorCode);
     // Enforce alpha on source image
     if (imageIsTrueColor($this->handle)) {
         imageAlphaBlending($this->handle, false);
         imageSaveAlpha($this->handle, true);
     }
     // Create background
     $bg = imageCreateTruecolor($width, $height);
     imageSaveAlpha($bg, empty($rgba['alpha']));
     // Allocate background color.
     $color = imageColorAllocateAlpha($bg, $rgba['red'], $rgba['green'], $rgba['blue'], $rgba['alpha']);
     // Fill background
     imageFill($bg, 0, 0, $color);
     // Apply image over background
     imageCopy($bg, $this->handle, 0, 0, 0, 0, $width, $height);
     // Move flattened result onto curent handle.
     // If handle was palette-based, it'll stay like that.
     imageCopy($this->handle, $bg, 0, 0, 0, 0, $width, $height);
     // Free up memory
     imageDestroy($bg);
     return;
 }
开发者ID:Rai-Ka,项目名称:joomla-cms,代码行数:45,代码来源:backgroundfill.php

示例3: addWatermark

 /**
  * function addWatermark
  *
  * @param string $imageFile
  * @param string $destinationFile
  */
 function addWatermark($imageFile, $destinationFile = true)
 {
     if ($destinationFile) {
         $destinationFile = $imageFile;
     }
     $watermark = @imagecreatefrompng($this->watermarkFile) or exit('Cannot open the watermark file.');
     imageAlphaBlending($watermark, false);
     imageSaveAlpha($watermark, true);
     $image_string = @file_get_contents($imageFile) or exit('Cannot open image file.');
     $image = @imagecreatefromstring($image_string) or exit('Not a valid image format.');
     $imageWidth = imageSX($image);
     $imageHeight = imageSY($image);
     $watermarkWidth = imageSX($watermark);
     $watermarkHeight = imageSY($watermark);
     if ($this->position == 'center') {
         $coordinate_X = ($imageWidth - $watermarkWidth) / 2;
         $coordinate_Y = ($imageHeight - $watermarkHeight) / 2;
     } else {
         $coordinate_X = $imageWidth - 5 - $watermarkWidth;
         $coordinate_Y = $imageHeight - 5 - $watermarkHeight;
     }
     imagecopy($image, $watermark, $coordinate_X, $coordinate_Y, 0, 0, $watermarkWidth, $watermarkHeight);
     if ($this->imageType == 'jpg') {
         imagejpeg($image, $destinationFile, 100);
     } elseif ($this->imageType == 'gif') {
         imagegif($image, $destinationFile);
     } elseif ($this->imageType == 'png') {
         imagepng($image, $destinationFile, 100);
     }
     imagedestroy($image);
     imagedestroy($watermark);
 }
开发者ID:yunsite,项目名称:demila,代码行数:38,代码来源:watermark.class.php

示例4: imgresize

 static function imgresize($photo_src, $width, $name)
 {
     $parametr = getimagesize($photo_src);
     list($width_orig, $height_orig) = getimagesize($photo_src);
     $ratio_orig = $width_orig / $height_orig;
     $new_width = $width;
     $new_height = $width / $ratio_orig;
     $newpic = imagecreatetruecolor($new_width, $new_height);
     imageAlphaBlending($newpic, false);
     imageSaveAlpha($newpic, true);
     switch ($parametr[2]) {
         case 1:
             $image = imagecreatefromgif($photo_src);
             break;
         case 2:
             $image = imagecreatefromjpeg($photo_src);
             break;
         case 3:
             $image = imagecreatefrompng($photo_src);
             break;
     }
     imagecopyresampled($newpic, $image, 0, 0, 0, 0, $new_width, $new_height, $width_orig, $height_orig);
     imagepng($newpic, $name);
     return true;
 }
开发者ID:awful0,项目名称:Webmasters-Forge-Ltd,代码行数:25,代码来源:Funct.php

示例5: balloonpng

function balloonpng($dir, $get_s, $get_color = null, $get_file = null)
{
    if ($get_s) {
        $smile = imagecreatefrompng($dir . "/images/smallballoontransp.png");
    } else {
        $smile = imagecreatefrompng($dir . "/images/bigballoontransp.png");
    }
    imageSaveAlpha($smile, true);
    if ($get_color != null) {
        $r = hexdec(substr($get_color, 0, 2));
        $g = hexdec(substr($get_color, 2, 2));
        $b = hexdec(substr($get_color, 4, 2));
        $kek = imagecolorallocate($smile, $r, $g, $b);
        if ($get_s) {
            imagefill($smile, 5, 5, $kek);
        } else {
            imagefill($smile, 12, 25, $kek);
        }
    }
    if ($get_file != null) {
        imagepng($smile, $get_file);
    } else {
        imagepng($smile);
    }
}
开发者ID:sbaldrich,项目名称:boca,代码行数:25,代码来源:fballoon.php

示例6: imageResize

 /**
  * Метод для изменения размера изображения.
  * @link URL Оригинал(Пример1) http://www.php.su/articles/?cat=graph&page=014
  */
 public function imageResize()
 {
     foreach ($this->data as $i => $param) {
         $descriptor = $param['descriptor'];
         $tmpImg = imagecreatetruecolor(20, 20);
         imageAlphaBlending($tmpImg, false);
         imageSaveAlpha($tmpImg, true);
         imagecopyresampled($tmpImg, $descriptor, 0, 0, 0, 0, 20, 20, $param['width'], $param['height']);
         switch ($param['type']) {
             case 'jpg':
                 $this->data[$i]['width'] = 20;
                 $this->data[$i]['height'] = 20;
                 imagejpeg($tmpImg, $param['source']);
                 imagedestroy($tmpImg);
                 break;
             case 'jpeg':
                 $this->data[$i]['width'] = 20;
                 $this->data[$i]['height'] = 20;
                 imagejpeg($tmpImg, $param['source']);
                 imagedestroy($tmpImg);
                 break;
             case 'png':
                 $this->data[$i]['width'] = 20;
                 $this->data[$i]['height'] = 20;
                 imagepng($tmpImg, $param['source']);
                 imagedestroy($tmpImg);
                 break;
         }
     }
 }
开发者ID:hungry-devel,项目名称:pixelArt,代码行数:34,代码来源:Image.class.php

示例7: resize

 public function resize($maxW = null, $maxH = null, $canEnlarge = false)
 {
     $src = $this->_rawImage;
     if ($maxW === null && $maxH === null) {
         return $src;
     }
     if (imageistruecolor($src)) {
         imageAlphaBlending($src, true);
         imageSaveAlpha($src, true);
     }
     $srcW = imagesx($src);
     $srcH = imagesy($src);
     $width = $maxW && ($canEnlarge || $maxW <= $srcW) ? $maxW : $srcW;
     $height = $maxH && ($canEnlarge || $maxH <= $srcW) ? $maxH : $srcH;
     $ratio_orig = $srcW / $srcH;
     if ($width / $height > $ratio_orig) {
         $width = $height * $ratio_orig;
     } else {
         $height = $width / $ratio_orig;
     }
     $maxW = $maxW ? $maxW : $width;
     $maxH = $maxH ? $maxH : $height;
     $img = imagecreatetruecolor($maxW, $maxH);
     $trans_colour = imagecolorallocatealpha($img, 0, 0, 0, 127);
     imagefill($img, 0, 0, $trans_colour);
     $offsetX = ($maxW - $width) / 2;
     $offsetY = ($maxH - $height) / 2;
     imagecopyresampled($img, $src, $offsetX, $offsetY, 0, 0, $width, $height, $srcW, $srcH);
     imagealphablending($img, true);
     imagesavealpha($img, true);
     return $img;
 }
开发者ID:tomk,项目名称:imagehelper,代码行数:32,代码来源:ImageHelper.php

示例8: hacknrollify

function hacknrollify($picfilename)
{
    $logofilename = "logo.png";
    $logoPicPath = "logopics/" . $logofilename;
    $originalPicPath = "originalpics/" . $picfilename;
    $editedfilename = "hnr_" . $picfilename;
    $editedPicPath = "editedpics/" . $editedfilename;
    // read the original image from file
    $profilepic = imagecreatefromjpeg($originalPicPath);
    $profilepicWidth = imagesx($profilepic);
    $profilepicHeight = imagesy($profilepic);
    // create the black image overlay
    $blackoverlay = imagecreate($profilepicWidth, $profilepicHeight);
    imagecolorallocate($blackoverlay, 0, 0, 0);
    // then merge the black and profilepic
    imagecopymerge($profilepic, $blackoverlay, 0, 0, 0, 0, $profilepicWidth, $profilepicHeight, 50);
    imagedestroy($blackoverlay);
    // merge the resized logo
    $logo = resizeImage($logoPicPath, $profilepicWidth - 80, 999999);
    imageAlphaBlending($logo, false);
    imageSaveAlpha($logo, true);
    $logoWidth = imagesx($logo);
    $logoHeight = imagesy($logo);
    $verticalOffset = $profilepicHeight / 2 - $logoHeight / 2;
    $horizontalOffset = 40;
    imagecopyresampled($profilepic, $logo, $horizontalOffset, $verticalOffset, 0, 0, $logoWidth, $logoHeight, $logoWidth, $logoHeight);
    $mergeSuccess = imagejpeg($profilepic, $editedPicPath);
    if (!$mergeSuccess) {
        echo "Image merge failed!";
    }
    imagedestroy($profilepic);
    imagedestroy($logo);
    return $editedPicPath;
}
开发者ID:nicholaslum444,项目名称:HacknRollify,代码行数:34,代码来源:lib_hacknrollify.php

示例9: __construct

 public function __construct($data)
 {
     $this->data = $data;
     $size = array_key_exists('global', $this->data) ? 'l' : 's';
     $text = !array_key_exists('text', $this->data) || strlen($this->data['text']) > 2 ? '??' : $this->data['text'];
     $font = filter_input(INPUT_SERVER, 'DOCUMENT_ROOT') . '/img/base/xkcd.ttf';
     $fg = $this->hex2rgb($this->colorGiven('fg') ? $this->data['fg'] : '000');
     $bg = $this->hex2rgb($this->colorGiven('bg') ? $this->data['bg'] : '0ff');
     $this->image = imagecreatefrompng($_SERVER['DOCUMENT_ROOT'] . '/img/base/fill_' . $size . '.png');
     imageAlphaBlending($this->image, true);
     imageSaveAlpha($this->image, true);
     $fc = imagecolorallocate($this->image, $fg['r'], $fg['g'], $fg['b']);
     $c = imagecolorallocate($this->image, $bg['r'], $bg['g'], $bg['b']);
     imagefill($this->image, imagesx($this->image) / 2, imagesy($this->image) / 2, $c);
     $outline = imagecreatefrompng($_SERVER['DOCUMENT_ROOT'] . '/img/base/outline_' . $size . '.png');
     imageAlphaBlending($outline, true);
     imageSaveAlpha($outline, true);
     imagecopy($this->image, $outline, 0, 0, 0, 0, imagesx($outline), imagesy($this->image));
     if ($size === 'l') {
         imagettftext($this->image, 12, 0, 3, 25, $fc, $_SERVER['DOCUMENT_ROOT'] . '/img/base/xkcd.ttf', 'global');
         $bounds = imagettfbbox(20, 0, $_SERVER['DOCUMENT_ROOT'] . '/img/base/xkcd.ttf', $text);
         imagettftext($this->image, 20, 0, (imagesx($this->image) - $bounds[4] - $bounds[0]) / 2, 50, $fc, $_SERVER['DOCUMENT_ROOT'] . '/img/base/xkcd.ttf', $text);
     } else {
         $bounds = imagettfbbox(15, 0, $_SERVER['DOCUMENT_ROOT'] . '/img/base/xkcd.ttf', $text);
         imagettftext($this->image, 15, 0, (imagesx($this->image) - $bounds[4] - $bounds[0]) / 2, 22, $fc, $_SERVER['DOCUMENT_ROOT'] . '/img/base/xkcd.ttf', $text);
     }
 }
开发者ID:Eupeodes,项目名称:gh,代码行数:27,代码来源:Marker.php

示例10: createImageImage

 /**
  * Create image resource from image file and alocate required memory
  * @param $imageFile
  * @return resource
  * @throws \Ip\Exception\Repository\Transform
  */
 protected function createImageImage($imageFile)
 {
     $this->getMemoryNeeded($imageFile);
     $mime = $this->getMimeType($imageFile);
     switch ($mime) {
         case IMAGETYPE_JPEG:
         case IMAGETYPE_JPEG2000:
             $originalSetting = ini_set('gd.jpeg_ignore_warning', 1);
             $image = imagecreatefromjpeg($imageFile);
             if ($originalSetting !== false) {
                 ini_set('gd.jpeg_ignore_warning', $originalSetting);
             }
             break;
         case IMAGETYPE_GIF:
             $image = imagecreatefromgif($imageFile);
             imageAlphaBlending($image, false);
             imageSaveAlpha($image, true);
             break;
         case IMAGETYPE_PNG:
             $image = imagecreatefrompng($imageFile);
             imageAlphaBlending($image, false);
             imageSaveAlpha($image, true);
             break;
         default:
             throw new \Ip\Exception\Repository\Transform("Incompatible type. Type detected: " . esc($mime), array('mime' => $mime));
     }
     return $image;
 }
开发者ID:Umz,项目名称:ImpressPages,代码行数:34,代码来源:Image.php

示例11: get_file

 private function get_file($type)
 {
     include_once 'Cache_Lite/Lite.php';
     $db = Input::getPath()->part(5);
     $baseLayer = Input::get("baselayer");
     $layers = Input::get("layers");
     $center = Input::get("center");
     $zoom = Input::get("zoom");
     $size = Input::get("size");
     $sizeArr = explode("x", Input::get("size"));
     $bbox = Input::get("bbox");
     $sql = Input::get("sql");
     $id = $db . "_" . $baseLayer . "_" . $layers . "_" . $center . "_" . $zoom . "_" . $size . "_" . $bbox . "_" . $sql;
     $lifetime = Input::get('lifetime') ?: 0;
     $options = array('cacheDir' => \app\conf\App::$param['path'] . "app/tmp/", 'lifeTime' => $lifetime);
     $Cache_Lite = new \Cache_Lite($options);
     if ($data = $Cache_Lite->get($id)) {
         //echo "Cached";
     } else {
         ob_start();
         $fileName = md5(time() . rand(10000, 99999) . microtime());
         $file = \app\conf\App::$param["path"] . "/app/tmp/_" . $fileName . "." . $type;
         $cmd = "wkhtmltoimage " . "--height {$sizeArr[1]} --disable-smart-width --width {$sizeArr[0]} --quality 90 --javascript-delay 1000 " . "\"" . "http://127.0.0.1" . "/api/v1/staticmap/html/{$db}?baselayer={$baseLayer}&layers={$layers}&center={$center}&zoom={$zoom}&size={$size}&bbox={$bbox}&sql={$sql}\" " . $file;
         //die($cmd);
         exec($cmd);
         switch ($type) {
             case "png":
                 $res = imagecreatefrompng($file);
                 break;
             case "jpg":
                 $res = imagecreatefromjpeg($file);
                 break;
         }
         if (!$res) {
             $response['success'] = false;
             $response['message'] = "Could not create image";
             $response['code'] = 406;
             header("HTTP/1.0 {$response['code']} " . \app\inc\Util::httpCodeText($response['code']));
             echo \app\inc\Response::toJson($response);
             exit;
         }
         header('Content-type: image/png');
         imageAlphaBlending($res, true);
         imageSaveAlpha($res, true);
         imagepng($res);
         // Cache script
         $data = ob_get_contents();
         $Cache_Lite->save($data, $id);
         ob_get_clean();
     }
     header("Content-type: image/png");
     echo $data;
     exit;
 }
开发者ID:ronaldoof,项目名称:geocloud2,代码行数:54,代码来源:Staticmap.php

示例12: writeWatermarkInfo

 public function writeWatermarkInfo(&$sourcefileId, $thumbnailMode, CacheFile $cacheFile)
 {
     if (!$this->config->isUsedWatermark() || $thumbnailMode) {
         return;
     }
     static $disable_alpha_warning;
     $watermarkfile = $this->config->getWatermarkFile();
     $align = $this->config->getWatermarkLeft();
     $valign = $this->config->getWatermarkTop();
     if ($this->config->getWatermarkTransparencyType() == 'alpha') {
         $transcolor = FALSE;
     } else {
         $transcolor = $this->config->getWatermarkTransparentColor();
     }
     $transparency = $this->config->getWatermarkTransparency();
     try {
         $watermarkfile_id = $this->loadWatermarkFile($watermarkfile);
     } catch (Exception $e) {
         return false;
     }
     @imageAlphaBlending($watermarkfile_id, false);
     $result = @imageSaveAlpha($watermarkfile_id, true);
     if (!$result) {
         if (!$disable_alpha_warning) {
             $msg = "Watermark problem: your server does not support alpha blending (requires GD 2.0.1+)";
             JLog::add($msg, JLog::WARNING);
         }
         $disable_alpha_warning = true;
         imagedestroy($watermarkfile_id);
         return false;
     }
     $offset_w = $cacheFile->offsetX();
     $offset_h = $cacheFile->offsetY();
     $w = $cacheFile->displayWidth();
     $h = $cacheFile->displayHeight();
     $watermarkfileWidth = imageSX($watermarkfile_id);
     $watermarkfileHeight = imageSY($watermarkfile_id);
     $watermarkOffsetX = $this->calcXOffsetForWatermark($align, $watermarkfileWidth, $offset_w, $w);
     $watermarkOffsetY = $this->calcYOffsetForWatermark($valign, $watermarkfileHeight, $offset_h, $h);
     $fileType = strtolower(pathinfo($watermarkfile, PATHINFO_EXTENSION));
     $sourcefileId = $this->upsampleImageIfNecessary($fileType, $sourcefileId);
     if ($transcolor !== false) {
         $transcolAsInt = intval(str_replace('#', '', $transcolor), 16);
         imagecolortransparent($watermarkfile_id, $transcolAsInt);
         // use transparent color
         imagecopymerge($sourcefileId, $watermarkfile_id, $watermarkOffsetX, $watermarkOffsetY, 0, 0, $watermarkfileWidth, $watermarkfileHeight, $transparency);
     } else {
         imagecopy($sourcefileId, $watermarkfile_id, $watermarkOffsetX, $watermarkOffsetY, 0, 0, $watermarkfileWidth, $watermarkfileHeight);
         // True
         // alphablend
     }
     imagedestroy($watermarkfile_id);
     return true;
 }
开发者ID:harryklein,项目名称:pkg_mosimage,代码行数:54,代码来源:WatermarkCreator.php

示例13: LoadPNG

function LoadPNG($imgname)
{
    /* Attempt to open */
    $im = @imagecreatefrompng($imgname);
    /* See if it failed */
    if (!$im) {
        $im = @imagecreatefrompng("/usr/local/share/pbi-manager/icons/default.png");
    }
    imageAlphaBlending($im, true);
    imageSaveAlpha($im, true);
    return $im;
}
开发者ID:shabesoglu,项目名称:pcbsd,代码行数:12,代码来源:pbiicon.php

示例14: build_monster

function build_monster($filename, $seed = '', $size = '')
{
    // init random seed
    if ($seed) {
        srand(hexdec(substr(md5($seed), 0, 6)));
    }
    // throw the dice for body parts
    $parts = array('legs' => rand(1, 5), 'hair' => rand(1, 5), 'arms' => rand(1, 5), 'body' => rand(1, 15), 'eyes' => rand(1, 15), 'mouth' => rand(1, 10));
    // create backgound
    $monster = @imagecreatetruecolor(120, 120) or die("GD image create failed");
    $white = imagecolorallocate($monster, 255, 255, 255);
    imagefill($monster, 0, 0, $white);
    // add parts
    foreach ($parts as $part => $num) {
        $file = dirname(__FILE__) . '/parts/' . $part . '_' . $num . '.png';
        $im = @imagecreatefrompng($file);
        if (!$im) {
            die('Failed to load ' . $file);
        }
        imageSaveAlpha($im, true);
        imagecopy($monster, $im, 0, 0, 0, 0, 120, 120);
        imagedestroy($im);
        // color the body
        if ($part == 'body') {
            $color = imagecolorallocate($monster, rand(20, 235), rand(20, 235), rand(20, 235));
            imagefill($monster, 60, 60, $color);
        }
    }
    // restore random seed
    if ($seed) {
        srand();
    }
    // resize if needed, then output
    if ($size && $size < 400) {
        $out = @imagecreatetruecolor($size, $size);
        if (!$out) {
            return false;
        }
        // Problems creating image!
        imagecopyresampled($out, $monster, 0, 0, 0, 0, $size, $size, 120, 120);
        imagepng($out, $filename);
        imagedestroy($out);
        imagedestroy($monster);
        return true;
    } else {
        //header ("Content-type: image/png");
        imagepng($monster, $filename);
        imagedestroy($monster);
        return true;
    }
}
开发者ID:vonnordmann,项目名称:Serendipity,代码行数:51,代码来源:monsterid.php

示例15: load

 /**
  * Load image
  *
  * @param string filename
  *
  * @return mixed none or a PEAR error object on error
  * @see PEAR::isError()
  */
 function load($image)
 {
     $this->uid = md5($_SERVER['REMOTE_ADDR']);
     $this->image = $image;
     $this->_get_image_details($image);
     $functionName = 'ImageCreateFrom' . $this->type;
     if (function_exists($functionName)) {
         $this->imageHandle = $functionName($this->image);
         if ($this->type == 'png') {
             imageAlphaBlending($this->imageHandle, false);
             imageSaveAlpha($this->imageHandle, true);
         }
     }
 }
开发者ID:blacksqr,项目名称:portable-nsd,代码行数:22,代码来源:GD.php


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