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


PHP ImageAlphaBlending函数代码示例

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


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

示例1: watermarkCreateText

 /**
  * Based on the Watermark function by Marek Malcherek  
  * http://www.malcherek.de
  *
  * @param string $color
  * @param string $wmFont
  * @param int $wmSize
  * @param int $wmOpaque
  */
 function watermarkCreateText($color = '000000', $wmFont, $wmSize = 10, $wmOpaque = 90)
 {
     // set font path
     $wmFontPath = NGGALLERY_ABSPATH . "fonts/" . $wmFont;
     if (!is_readable($wmFontPath)) {
         return;
     }
     // This function requires both the GD library and the FreeType library.
     if (!function_exists('ImageTTFBBox')) {
         return;
     }
     $words = preg_split('/ /', $this->watermarkText);
     $lines = array();
     $line = '';
     $watermark_image_width = 0;
     // attempt adding a new word until the width is too large; then start a new line and start again
     foreach ($words as $word) {
         // sanitize the text being input; imagettftext() can be sensitive
         $TextSize = $this->ImageTTFBBoxDimensions($wmSize, 0, $wmFontPath, $line . preg_replace('~^(&([a-zA-Z0-9]);)~', htmlentities('${1}'), mb_convert_encoding($word, "HTML-ENTITIES", "UTF-8")));
         if ($watermark_image_width == 0) {
             $watermark_image_width = $TextSize['width'];
         }
         if ($TextSize['width'] > $this->newDimensions['newWidth']) {
             $lines[] = trim($line);
             $line = '';
         } else {
             if ($TextSize['width'] > $watermark_image_width) {
                 $watermark_image_width = $TextSize['width'];
             }
         }
         $line .= $word . ' ';
     }
     $lines[] = trim($line);
     // use this string to determine our largest possible line height
     $line_dimensions = $this->ImageTTFBBoxDimensions($wmSize, 0, $wmFontPath, 'MXQJALYmxqjabdfghjklpqry019`@$^&*(,!132');
     $line_height = $line_dimensions['height'] * 1.05;
     // Create an image to apply our text to
     $this->workingImage = ImageCreateTrueColor($watermark_image_width, count($lines) * $line_height);
     ImageSaveAlpha($this->workingImage, true);
     ImageAlphaBlending($this->workingImage, false);
     $bgText = imagecolorallocatealpha($this->workingImage, 255, 255, 255, 127);
     imagefill($this->workingImage, 0, 0, $bgText);
     $wmTransp = 127 - $wmOpaque * 1.27;
     $rgb = $this->hex2rgb($color, false);
     $TextColor = imagecolorallocatealpha($this->workingImage, $rgb[0], $rgb[1], $rgb[2], $wmTransp);
     // Put text on the image, line-by-line
     $y_pos = $wmSize;
     foreach ($lines as $line) {
         imagettftext($this->workingImage, $wmSize, 0, 0, $y_pos, $TextColor, $wmFontPath, $line);
         $y_pos += $line_height;
     }
     $this->watermarkImgPath = $this->workingImage;
     return;
 }
开发者ID:hiaedenis,项目名称:nextgen-gallery,代码行数:63,代码来源:class.ngglegacy_thumbnail.php

示例2: _addWaterMark

 /**
  * Agrega una marca de agua a la foto
  * @param string $absolutePath
  */
 private function _addWaterMark($absolutePath)
 {
     $DOC_ROOT = $this->_CI->input->server('DOCUMENT_ROOT') . "/";
     if (FALSE === is_file($absolutePath)) {
         return FALSE;
     }
     switch (TRUE) {
         case stristr($absolutePath, 'jpg'):
             $photoImage = ImageCreateFromJpeg("{$absolutePath}");
             break;
         case stristr($absolutePath, 'gif'):
             $photoImage = ImageCreateFromGIF("{$absolutePath}");
             break;
         case stristr($absolutePath, 'png'):
             $photoImage = ImageCreateFromPNG("{$absolutePath}");
             break;
     }
     ImageAlphaBlending($photoImage, true);
     // Añadimos aquí el fichero de marca de agua.
     $logoImage = ImageCreateFromPNG($DOC_ROOT . "assets/imagenes/marca_agua_telam.png");
     $logoW = ImageSX($logoImage);
     $logoH = ImageSY($logoImage);
     $tamanox = imagesx($photoImage);
     $ubicacionX = ($tamanox - $logoW) / 2;
     $tamanoy = imagesy($photoImage);
     $ubicacionY = ($tamanoy - $logoH) / 2;
     ImageCopy($photoImage, $logoImage, $ubicacionX, $ubicacionY, 0, 0, $logoW, $logoH);
     imagejpeg($photoImage, $absolutePath);
     ImageDestroy($photoImage);
     ImageDestroy($logoImage);
 }
开发者ID:rino7,项目名称:ci_media_manager,代码行数:35,代码来源:generador_thumb.php

示例3: marcadeagua

function marcadeagua($img_original, $img_marcadeagua, $img_nueva, $calidad)
{
    // obtener datos de la fotografia
    $info_original = getimagesize($img_original);
    $anchura_original = $info_original[0];
    $altura_original = $info_original[1];
    // obtener datos de la "marca de agua"
    $info_marcadeagua = getimagesize($img_marcadeagua);
    $anchura_marcadeagua = $info_marcadeagua[0];
    $altura_marcadeagua = $info_marcadeagua[1];
    // calcular la posición donde debe copiarse la "marca de agua" en la fotografia
    /* 
    // Posicion: Centrado
    $horizmargen = ($anchura_original - $anchura_marcadeagua)/2; 
    $vertmargen = ($altura_original - $altura_marcadeagua)/2; 
    */
    // Posicion: abajo a la izquierda
    $horizmargen = 10;
    $vertmargen = $altura_original - $altura_marcadeagua - 10;
    // crear imagen desde el original
    $original = ImageCreateFromJPEG($img_original);
    ImageAlphaBlending($original, true);
    // crear nueva imagen desde la marca de agua
    $marcadeagua = ImageCreateFromPNG($img_marcadeagua);
    // copiar la "marca de agua" en la fotografia
    ImageCopy($original, $marcadeagua, $horizmargen, $vertmargen, 0, 0, $anchura_marcadeagua, $altura_marcadeagua);
    // guardar la nueva imagen
    ImageJPEG($original, $img_nueva, $calidad);
    // cerrar las imágenes
    ImageDestroy($original);
    ImageDestroy($marcadeagua);
}
开发者ID:jorgea3004,项目名称:GeneraGaleria,代码行数:32,代码来源:index.php

示例4: watermark

 function watermark($pngImage, $left = 0, $top = 0)
 {
     ImageAlphaBlending($this->image, true);
     $layer = ImageCreateFromPNG($pngImage);
     $logoW = ImageSX($layer);
     $logoH = ImageSY($layer);
     ImageCopy($this->image, $layer, $left, $top, 0, 0, $logoW, $logoH);
 }
开发者ID:centaurustech,项目名称:BenFund,代码行数:8,代码来源:resize.php

示例5: 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;
		}
	}
开发者ID:robbiespire,项目名称:paQui,代码行数:10,代码来源:Image.php

示例6: copy_image

 public function copy_image($url, $logo)
 {
     $bwidth = imagesx($url);
     $bheight = imagesy($url);
     $lwidth = imagesx($logo);
     $lheight = imagesy($logo);
     $src_x = $bwidth - ($lwidth + 5);
     $src_y = $bheight - ($lheight + 5);
     ImageAlphaBlending($url, true);
     ImageCopy($url, $logo, $src_x, $src_y, 0, 0, $lwidth, $lheight);
 }
开发者ID:saulhoward,项目名称:oedipus-decision-maker,代码行数:11,代码来源:Oedipus_FrameImageHelper.inc.php

示例7: 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;
 }
开发者ID:Rikisha,项目名称:proj,代码行数:50,代码来源:convolution.php

示例8: watermark

 /**
 	// watermark
 	// source : php.net
 */
 function watermark($name, $ext)
 {
     ($hook = kleeja_run_hook('watermark_func_kljuploader')) ? eval($hook) : null;
     //run hook
     if (!file_exists($name)) {
         return;
     }
     if (strpos($ext, 'jp') !== false) {
         $src_img = @imagecreatefromjpeg($name);
     } elseif (strpos($ext, 'png') !== false) {
         $src_img = @imagecreatefrompng($name);
     } elseif (strpos($ext, 'gif') !== false) {
         $src_img = @imagecreatefromgif($name);
     } else {
         return;
     }
     if (file_exists('images/watermark.gif')) {
         $src_logo = imagecreatefromgif('images/watermark.gif');
     } elseif (file_exists('images/watermark.png')) {
         $src_logo = imagecreatefrompng('images/watermark.png');
     }
     $bwidth = @imageSX($src_img);
     $bheight = @imageSY($src_img);
     $lwidth = @imageSX($src_logo);
     $lheight = @imageSY($src_logo);
     //fix bug for 1beta3
     if ($bwidth > 160 && $bheight > 130) {
         $src_x = $bwidth - ($lwidth + 5);
         $src_y = $bheight - ($lheight + 5);
         @ImageAlphaBlending($src_img, true);
         @ImageCopy($src_img, $src_logo, $src_x, $src_y, 0, 0, $lwidth, $lheight);
         if (strpos($ext, 'jp') !== false) {
             @imagejpeg($src_img, $name);
         } elseif (strpos($ext, 'png') !== false) {
             @imagepng($src_img, $name);
         } elseif (strpos($ext, 'gif') !== false) {
             @imagegif($src_img, $name);
         }
     } else {
         return false;
     }
 }
开发者ID:Amine12boutouil,项目名称:Kleeja-2.0.0-alpha,代码行数:46,代码来源:KljUploader.php

示例9: cs_resample

function cs_resample($image, $target, $max_width, $max_height)
{
    $gd_info = gd_info();
    $im_info = array();
    if (file_exists($image)) {
        $im_info = getimagesize($image);
    } else {
        cs_error(__FILE__, 'Image file does not exist: "' . $image . '"');
        return false;
    }
    if ($im_info[2] == 1 and !empty($gd_info["GIF Read Support"])) {
        $src = ImageCreateFromGIF($image);
    } elseif ($im_info[2] == 2 and (!empty($gd_info["JPG Support"]) or !empty($gd_info["JPEG Support"]))) {
        $src = ImageCreateFromJPEG($image);
    } elseif ($im_info[2] == 3 and !empty($gd_info["PNG Support"])) {
        $src = ImageCreateFromPNG($image);
    } else {
        cs_error(__FILE__, 'Image filetype is not supported: "' . $image . '"');
        return false;
    }
    $factor = max($im_info[1] / $max_height, $im_info[0] / $max_width);
    $im_new[0] = floor($im_info[0] / $factor);
    $im_new[1] = floor($im_info[1] / $factor);
    $dst = ImageCreateTrueColor($im_new[0], $im_new[1]);
    ImageAlphaBlending($dst, false);
    ImageSaveAlpha($dst, true);
    ImageCopyResampled($dst, $src, 0, 0, 0, 0, $im_new[0], $im_new[1], $im_info[0], $im_info[1]);
    if ($im_info[2] == 1) {
        $return = ImageGIF($dst, $target) ? 1 : 0;
    } elseif ($im_info[2] == 2) {
        $return = ImageJPEG($dst, $target, 100) ? 1 : 0;
    } elseif ($im_info[2] == 3) {
        $return = ImagePNG($dst, $target) ? 1 : 0;
    } else {
        cs_error(__FILE__, 'Failed to write resampled image file: "' . $target . '"');
        return false;
    }
    return $return;
}
开发者ID:aberrios,项目名称:WEBTHESGO,代码行数:39,代码来源:gd.php

示例10: watermarkCreateText

 /**
  * Based on the Watermark function by Marek Malcherek
  * http://www.malcherek.de
  *
  * @param string $color
  * @param string $wmFont
  * @param int $wmSize
  * @param int $wmOpaque
  */
 function watermarkCreateText($color = '000000', $wmFont, $wmSize = 10, $wmOpaque = 90)
 {
     // set font path
     $wmFontPath = NGGALLERY_ABSPATH . "fonts/" . $wmFont;
     if (!is_readable($wmFontPath)) {
         return;
     }
     // This function requires both the GD library and the FreeType library.
     if (!function_exists('ImageTTFBBox')) {
         return;
     }
     $TextSize = @ImageTTFBBox($wmSize, 0, $wmFontPath, $this->watermarkText) or die;
     $TextWidth = abs($TextSize[2]) + abs($TextSize[0]);
     $TextHeight = abs($TextSize[7]) + abs($TextSize[1]);
     // Create Image for Text
     $this->workingImage = ImageCreateTrueColor($TextWidth, $TextHeight);
     ImageSaveAlpha($this->workingImage, true);
     ImageAlphaBlending($this->workingImage, false);
     $bgText = imagecolorallocatealpha($this->workingImage, 255, 255, 255, 127);
     imagefill($this->workingImage, 0, 0, $bgText);
     $wmTransp = 127 - $wmOpaque * 1.27;
     $rgb = $this->hex2rgb($color, false);
     $TextColor = imagecolorallocatealpha($this->workingImage, $rgb[0], $rgb[1], $rgb[2], $wmTransp);
     // Create Text on image
     imagettftext($this->workingImage, $wmSize, 0, 0, abs($TextSize[5]), $TextColor, $wmFontPath, $this->watermarkText);
     $this->watermarkImgPath = $this->workingImage;
     return;
 }
开发者ID:ayoayco,项目名称:upbeat,代码行数:37,代码来源:gd.thumbnail.inc.php

示例11: oos_watermark

function oos_watermark($pic, $image_new, $quality = '100')
{
    $dst_img = '';
    $imageInfo = GetImageSize($pic);
    $width = $imageInfo[0];
    $height = $imageInfo[1];
    $logoinfo = getimagesize(OOS_WATERMARK_LOGO);
    $logowidth = $logoinfo[0];
    $logoheight = $logoinfo[1];
    if (function_exists('imagecreatefromjpeg')) {
        // check if php with gd-lib-support is installed
        if ($imageInfo[2] == 1) {
            if (function_exists('imagecreatefromgif')) {
                $src_img = imagecreatefromgif($pic);
            }
        }
        if ($imageInfo[2] == 2) {
            if (function_exists('imagecreatefromjpeg')) {
                $src_img = imagecreatefromjpeg($pic);
            }
        }
        if ($imageInfo[2] == 3) {
            if (function_exists('imagecreatefrompng')) {
                $src_img = imagecreatefrompng($pic);
            }
        }
        if ($src_img) {
            if (OOS_BIGIMAGE_WIDTH || OOS_BIGIMAGE_HEIGHT) {
                // proportionaler resize; width oder height ist die maximale Größe
                $x = OOS_BIGIMAGE_WIDTH / $width;
                $y = OOS_BIGIMAGE_HEIGHT / $height;
                if ($y > 0 && $y < $x || $x == 0) {
                    $x = $y;
                }
                $width_big = $width * $x;
                $height_big = $height * $x;
                $width = $width_big;
                $height = $height_big;
                if (OOS_GD_LIB_VERSION == '2') {
                    $dst_img = imagecreatetruecolor($width_big, $height_big);
                    imagecopyresampled($dst_img, $src_img, 0, 0, 0, 0, $width_big, $height_big, imagesx($src_img), imagesy($src_img));
                } else {
                    $dst_img = imagecreate($width_big, $height_big);
                    imagecopyresized($dst_img, $src_img, 0, 0, 0, 0, $width_big, $height_big, imagesx($src_img), imagesy($src_img));
                }
            } else {
                $dst_img = $src_img;
            }
            $hori = $width - $logowidth;
            $vert = $height - $logoheight;
            $horizmargin = round($hori / 2);
            $vertmargin = round($vert / 2);
            ImageAlphaBlending($dst_img, true);
            $logoImage = ImageCreateFromPNG(OOS_WATERMARK_LOGO);
            $logoW = ImageSX($logoImage);
            $logoH = ImageSY($logoImage);
            ImageCopy($dst_img, $logoImage, $horizmargin, $vertmargin, 0, 0, $logoW, $logoH);
            // Copy Picture
            $fh = fopen($image_new, 'w');
            fclose($fh);
            if ($imageInfo[2] == 1) {
                imagegif($dst_img, $image_new);
            }
            if ($imageInfo[2] == 2) {
                imagejpeg($dst_img, $image_new, $quality);
            }
            if ($imageInfo[2] == 3) {
                imagepng($dst_img, $image_new);
            }
            return true;
        }
    }
    // pic couldn't be resized, so copy original
    copy($pic, $image_new);
    return false;
}
开发者ID:BackupTheBerlios,项目名称:oos-svn,代码行数:76,代码来源:function_image_resize.php

示例12: replaceTransparentWhite

 function replaceTransparentWhite($im)
 {
     $src_w = ImageSX($im);
     $src_h = ImageSY($im);
     $backgroundimage = imagecreatetruecolor($src_w, $src_h);
     $white = ImageColorAllocate($backgroundimage, 255, 255, 255);
     ImageFill($backgroundimage, 0, 0, $white);
     ImageAlphaBlending($backgroundimage, TRUE);
     imagecopy($backgroundimage, $im, 0, 0, 0, 0, $src_w, $src_h);
     return $backgroundimage;
 }
开发者ID:hyrmedia,项目名称:modules,代码行数:11,代码来源:class.imageconverter.inc.php

示例13: elseif

    // great
} elseif (@$_GET['new']) {
    // generate a blank image resource of the specified size/background color/opacity
    if ($phpThumb->w <= 0 || $phpThumb->h <= 0) {
        $phpThumb->ErrorImage('"w" and "h" parameters required for "new"');
    }
    @(list($bghexcolor, $opacity) = explode('|', $_GET['new']));
    if (!phpthumb_functions::IsHexColor($bghexcolor)) {
        $phpThumb->ErrorImage('BGcolor parameter for "new" is not valid');
    }
    $opacity = strlen($opacity) ? $opacity : 100;
    if ($phpThumb->gdimg_source = phpthumb_functions::ImageCreateFunction($phpThumb->w, $phpThumb->h)) {
        $alpha = (100 - min(100, max(0, $opacity))) * 1.27;
        if ($alpha) {
            $phpThumb->setParameter('is_alpha', true);
            ImageAlphaBlending($phpThumb->gdimg_source, false);
            ImageSaveAlpha($phpThumb->gdimg_source, true);
        }
        $new_background_color = phpthumb_functions::ImageHexColorAllocate($phpThumb->gdimg_source, $bghexcolor, false, $alpha);
        ImageFilledRectangle($phpThumb->gdimg_source, 0, 0, $phpThumb->w, $phpThumb->h, $new_background_color);
    } else {
        $phpThumb->ErrorImage('failed to create "new" image (' . $phpThumb->w . 'x' . $phpThumb->h . ')');
    }
} elseif (!$phpThumb->src) {
    $phpThumb->ErrorImage('Usage: ' . $_SERVER['PHP_SELF'] . '?src=/path/and/filename.jpg' . "\n" . 'read Usage comments for details');
} elseif (preg_match('/^(f|ht)tp\\:\\/\\//i', $phpThumb->src)) {
    $phpThumb->DebugMessage('$phpThumb->src (' . $phpThumb->src . ') is remote image, attempting to download', __FILE__, __LINE__);
    if ($phpThumb->config_http_user_agent) {
        $phpThumb->DebugMessage('Setting "user_agent" to "' . $phpThumb->config_http_user_agent . '"', __FILE__, __LINE__);
        ini_set('user_agent', $phpThumb->config_http_user_agent);
    }
开发者ID:CrazyBobik,项目名称:allotaxi.test,代码行数:31,代码来源:phpThumb.php

示例14: SaveQValueAssociationImage

 private function SaveQValueAssociationImage()
 {
     if (!array_key_exists('associationimage', $_FILES) || $_FILES['associationimage']['error'] !== 0 || strtolower(substr($_FILES['associationimage']['type'], 0, 6)) !== 'image/') {
         return false;
     }
     // Attempt to set the memory limit
     setImageFileMemLimit($_FILES['associationimage']['tmp_name']);
     // Generate the destination path
     $randomDir = strtolower(chr(rand(65, 90)));
     $destPath = realpath(ISC_BASE_PATH . '/' . GetConfig('ImageDirectory'));
     if (!is_dir($destPath . '/' . $randomDir)) {
         if (!@mkdir($destPath . '/' . $randomDir, 0777)) {
             $randomDir = '';
         }
     }
     $destFile = GenRandFileName($_FILES['associationimage']['name'], 'category');
     $destPath = $destPath . '/' . $randomDir . '/' . $destFile;
     $returnPath = $randomDir . '/' . $destFile;
     $tmp = explode('.', $_FILES['associationimage']['name']);
     $ext = strtolower($tmp[count($tmp) - 1]);
     if ($ext == 'jpg') {
         $srcImg = imagecreatefromjpeg($_FILES['associationimage']['tmp_name']);
     } else {
         if ($ext == 'gif') {
             $srcImg = imagecreatefromgif($_FILES['associationimage']['tmp_name']);
             if (!function_exists('imagegif')) {
                 $gifHack = 1;
             }
         } else {
             $srcImg = imagecreatefrompng($_FILES['associationimage']['tmp_name']);
         }
     }
     $srcWidth = imagesx($srcImg);
     $srcHeight = imagesy($srcImg);
     $widthLimit = GetConfig('BrandImageWidth');
     $heightLimit = GetConfig('BrandImageHeight');
     // If the image is small enough, simply move it and leave it as is
     if ($srcWidth <= $widthLimit && $srcHeight <= $heightLimit) {
         imagedestroy($srcImg);
         move_uploaded_file($_FILES['associationimage']['tmp_name'], $destPath);
         return $returnPath;
     }
     // Otherwise, the image needs to be resized
     $attribs = getimagesize($_FILES['associationimage']['tmp_name']);
     $width = $attribs[0];
     $height = $attribs[1];
     if ($width > $widthLimit) {
         $height = ceil($widthLimit / $width * $height);
         $width = $widthLimit;
     }
     if ($height > $heightLimit) {
         $width = ceil($heightLimit / $height * $width);
         $height = $heightLimit;
     }
     $dstImg = imagecreatetruecolor($width, $height);
     if ($ext == "gif" && !isset($gifHack)) {
         $colorTransparent = imagecolortransparent($srcImg);
         imagepalettecopy($srcImg, $dstImg);
         imagecolortransparent($dstImg, $colorTransparent);
         imagetruecolortopalette($dstImg, true, 256);
     } else {
         if ($ext == "png") {
             ImageColorTransparent($dstImg, ImageColorAllocate($dstImg, 0, 0, 0));
             ImageAlphaBlending($dstImg, false);
         }
     }
     imagecopyresampled($dstImg, $srcImg, 0, 0, 0, 0, $width, $height, $srcWidth, $srcHeight);
     if ($ext == "jpg") {
         imagejpeg($dstImg, $destPath, 100);
     } else {
         if ($ext == "gif") {
             if (isset($gifHack) && $gifHack == true) {
                 $thumbFile = isc_substr($destPath, 0, -3) . "jpg";
                 imagejpeg($dstImg, $destPath, 100);
             } else {
                 imagegif($dstImg, $destPath);
             }
         } else {
             imagepng($dstImg, $destPath);
         }
     }
     @imagedestroy($dstImg);
     @imagedestroy($srcImg);
     @unlink($_FILES['associationimage']['tmp_name']);
     // Change the permissions on the thumbnail file
     isc_chmod($returnPath, ISC_WRITEABLE_FILE_PERM);
     return $returnPath;
 }
开发者ID:nirvana-info,项目名称:old_bak,代码行数:88,代码来源:class.qvalue.associations_oct12.php

示例15: 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);
开发者ID:zmwebdev,项目名称:PHPcookbook-code-3ed,代码行数:24,代码来源:thumbnail3.php


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