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


PHP imageAntiAlias函数代码示例

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


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

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

示例2: draw

 /**
  * Draws the pie chart, with optional supersampled anti-aliasing.
  * @param int $aa
  */
 public function draw($aa = 4)
 {
     $this->canvas = imageCreateTrueColor($this->width, $this->height);
     // Set anti-aliasing for the pie chart.
     imageAntiAlias($this->canvas, true);
     imageFilledRectangle($this->canvas, 0, 0, $this->width, $this->height, $this->_convertColor($this->backgroundColor));
     $total = 0;
     $sliceStart = -90;
     // Start at 12 o'clock.
     $titleHeight = $this->_drawTitle();
     $legendWidth = $this->_drawLegend($titleHeight);
     // Account for the space occupied by the legend and its padding.
     $pieCentreX = ($this->width - $legendWidth) / 2;
     // Account for the space occupied by the title.
     $pieCentreY = $titleHeight + ($this->height - $titleHeight) / 2;
     // 10% padding on the top and bottom of the pie.
     $pieDiameter = round(min($this->width - $legendWidth, $this->height - $titleHeight) * 0.85);
     foreach ($this->slices as $slice) {
         $total += $slice['value'];
     }
     // If anti-aliasing is enabled, we supersample the pie to work around
     // the fact that GD does not provide anti-aliasing natively.
     if ($aa > 0) {
         $ssDiameter = $pieDiameter * $aa;
         $ssCentreX = $ssCentreY = $ssDiameter / 2;
         $superSample = imageCreateTrueColor($ssDiameter, $ssDiameter);
         imageFilledRectangle($superSample, 0, 0, $ssDiameter, $ssDiameter, $this->_convertColor($this->backgroundColor));
         foreach ($this->slices as $slice) {
             $sliceWidth = 360 * $slice['value'] / $total;
             // Skip slices that are too small to draw / be visible.
             if ($sliceWidth == 0) {
                 continue;
             }
             $sliceEnd = $sliceStart + $sliceWidth;
             imageFilledArc($superSample, $ssCentreX, $ssCentreY, $ssDiameter, $ssDiameter, $sliceStart, $sliceEnd, $this->_convertColor($slice['color']), IMG_ARC_PIE);
             // Move along to the next slice.
             $sliceStart = $sliceEnd;
         }
         imageCopyResampled($this->canvas, $superSample, $pieCentreX - $pieDiameter / 2, $pieCentreY - $pieDiameter / 2, 0, 0, $pieDiameter, $pieDiameter, $ssDiameter, $ssDiameter);
         imageDestroy($superSample);
     } else {
         // Draw the slices.
         foreach ($this->slices as $slice) {
             $sliceWidth = 360 * $slice['value'] / $total;
             // Skip slices that are too small to draw / be visible.
             if ($sliceWidth == 0) {
                 continue;
             }
             $sliceEnd = $sliceStart + $sliceWidth;
             imageFilledArc($this->canvas, $pieCentreX, $pieCentreY, $pieDiameter, $pieDiameter, $sliceStart, $sliceEnd, $this->_convertColor($slice['color']), IMG_ARC_PIE);
             // Move along to the next slice.
             $sliceStart = $sliceEnd;
         }
     }
 }
开发者ID:samchristy,项目名称:piechart,代码行数:59,代码来源:PieChartGD.php

示例3: createThumbs

 public function createThumbs($thumb_size)
 {
     $thumb = imageCreateTrueColor($thumb_size['width'], $thumb_size['height']);
     if ($thumb === false) {
         throw new Exception('cannot create img_thumb file');
     }
     $resX = floor(imagesx($this->_orig_img) * ($thumb_size['height'] / imagesy($this->_orig_img)));
     $resY = $thumb_size['height'];
     imageAntiAlias($thumb, true);
     imagecopyresized($thumb, $this->_orig_img, 0, 0, 0, 0, $resX, $resY, imagesx($this->_orig_img), imagesy($this->_orig_img));
     if (!imageJPEG($thumb, $this->_save_path . 'thumbs_' . $this->_new_img_name, 100)) {
         imagedestroy($thumb);
         throw new Exception('cannot save img_thumbs file');
     }
     imagedestroy($thumb);
     return $this;
 }
开发者ID:alexposseda,项目名称:events,代码行数:17,代码来源:image.class.php

示例4: _image_creer_vignette


//.........这里部分代码省略.........
                }
                if (!@file_exists($vignette)) {
                    spip_log("echec netpbm-gif sur {$vignette}");
                    return;
                }
            } else {
                if ($format == "png") {
                    $pngtopnm_command = str_replace("pnmscale", "pngtopnm", _PNMSCALE_COMMAND);
                    exec("{$pngtopnm_command} {$image} | " . _PNMSCALE_COMMAND . " -width {$destWidth} | {$pnmtojpeg_command} > {$vignette}");
                    if (!($s = @filesize($vignette))) {
                        spip_unlink($vignette);
                    }
                    if (!@file_exists($vignette)) {
                        spip_log("echec netpbm-png sur {$vignette}");
                        return;
                    }
                }
            }
        }
    } elseif ($process == 'gd1' or $process == 'gd2') {
        if (!function_exists('gd_info')) {
            spip_log("Librairie GD absente !", _LOG_ERREUR);
            return;
        }
        if (_IMG_GD_MAX_PIXELS && $srcWidth * $srcHeight > _IMG_GD_MAX_PIXELS) {
            spip_log("vignette gd1/gd2 impossible : " . $srcWidth * $srcHeight . "pixels");
            return;
        }
        $destFormat = $format_sortie;
        if (!$destFormat) {
            spip_log("pas de format pour {$image}");
            return;
        }
        $fonction_imagecreatefrom = $valeurs['fonction_imagecreatefrom'];
        if (!function_exists($fonction_imagecreatefrom)) {
            return '';
        }
        $srcImage = @$fonction_imagecreatefrom($image);
        if (!$srcImage) {
            spip_log("echec gd1/gd2");
            return;
        }
        // Initialisation de l'image destination
        $destImage = null;
        if ($process == 'gd2' and $destFormat != "gif") {
            $destImage = ImageCreateTrueColor($destWidth, $destHeight);
        }
        if (!$destImage) {
            $destImage = ImageCreate($destWidth, $destHeight);
        }
        // Recopie de l'image d'origine avec adaptation de la taille
        $ok = false;
        if ($process == 'gd2' and function_exists('ImageCopyResampled')) {
            if ($format == "gif") {
                // Si un GIF est transparent,
                // fabriquer un PNG transparent
                $transp = imagecolortransparent($srcImage);
                if ($transp > 0) {
                    $destFormat = "png";
                }
            }
            if ($destFormat == "png") {
                // Conserver la transparence
                if (function_exists("imageAntiAlias")) {
                    imageAntiAlias($destImage, true);
                }
                @imagealphablending($destImage, false);
                @imagesavealpha($destImage, true);
            }
            $ok = @ImageCopyResampled($destImage, $srcImage, 0, 0, 0, 0, $destWidth, $destHeight, $srcWidth, $srcHeight);
        }
        if (!$ok) {
            $ok = ImageCopyResized($destImage, $srcImage, 0, 0, 0, 0, $destWidth, $destHeight, $srcWidth, $srcHeight);
        }
        // Sauvegarde de l'image destination
        $valeurs['fichier_dest'] = $vignette = "{$destination}.{$destFormat}";
        $valeurs['format_dest'] = $format = $destFormat;
        _image_gd_output($destImage, $valeurs);
        if ($srcImage) {
            ImageDestroy($srcImage);
        }
        ImageDestroy($destImage);
    }
    $size = @getimagesize($vignette);
    // Gaffe: en safe mode, pas d'acces a la vignette,
    // donc risque de balancer "width='0'", ce qui masque l'image sous MSIE
    if ($size[0] < 1) {
        $size[0] = $destWidth;
    }
    if ($size[1] < 1) {
        $size[1] = $destHeight;
    }
    $retour['width'] = $largeur = $size[0];
    $retour['height'] = $hauteur = $size[1];
    $retour['fichier'] = $vignette;
    $retour['format'] = $format;
    $retour['date'] = @filemtime($vignette);
    // renvoyer l'image
    return $retour;
}
开发者ID:xablen,项目名称:Semaine14_SPIP_test,代码行数:101,代码来源:filtres_images_lib_mini.php

示例5: image_masque

function image_masque($im, $masque, $pos = "")
{
    // Passer, en plus de l'image d'origine,
    // une image de "masque": un fichier PNG24 transparent.
    // Le decoupage se fera selon la transparence du "masque",
    // et les couleurs seront eclaircies/foncees selon de couleur du masque.
    // Pour ne pas modifier la couleur, le masque doit etre en gris 50%.
    //
    // Si l'image source est plus grande que le masque, alors cette image est reduite a la taille du masque.
    // Sinon, c'est la taille de l'image source qui est utilisee.
    //
    // $pos est une variable libre, qui permet de passer left=..., right=..., bottom=..., top=...
    // dans ce cas, le masque est place a ces positions sur l'image d'origine,
    // et evidemment cette image d'origine n'est pas redimensionnee
    //
    // Positionnement horizontal: text-align=left, right, center
    // Positionnement vertical : vertical-align=top, bottom, middle
    // (les positionnements left, right, top, left sont relativement inutiles, mais coherence avec CSS)
    //
    // Choix du mode de fusion: mode=masque, normal, eclaircir, obscurcir, produit, difference, ecran, superposer, lumiere_dure, teinte, saturation, valeur
    // https://en.wikipedia.org/wiki/Blend_modes
    // masque: mode par defaut
    // normal: place la nouvelle image par dessus l'ancienne
    // eclaircir: place uniquement les points plus clairs
    // obscurcir: place uniquement les points plus fonc'es
    // produit: multiplie par le masque (points noirs rendent l'image noire, points blancs ne changent rien)
    // difference: remplit avec l'ecart entre les couleurs d'origine et du masque
    // ecran: effet inverse de 'produit' -> l'image resultante est plus claire
    // superposer: combine les modes 'produit' et 'ecran' -> les parties claires sont eclaircies, les parties sombres assombries.
    // lumiere_dure: equivalent a 'superposer', sauf que l'image du bas et du haut sont inversees.
    // teinte: utilise la teinte du masque
    // saturation: utilise la saturation du masque
    // valeur: utilise la valeur du masque
    $mode = "masque";
    $numargs = func_num_args();
    $arg_list = func_get_args();
    $variable = array();
    $texte = $arg_list[0];
    for ($i = 1; $i < $numargs; $i++) {
        if (($p = strpos($arg_list[$i], "=")) !== false) {
            $nom_variable = substr($arg_list[$i], 0, $p);
            $val_variable = substr($arg_list[$i], $p + 1);
            $variable["{$nom_variable}"] = $val_variable;
            $defini["{$nom_variable}"] = 1;
        }
    }
    if (isset($defini["mode"]) and $defini["mode"]) {
        $mode = $variable["mode"];
    }
    // utiliser _image_valeurs_trans pour accepter comme masque :
    // - une balise <img src='...' />
    // - une image avec un timestamp ?01234
    $mask = _image_valeurs_trans($masque, "source-image_masque", "png", null, true);
    if (!$mask) {
        return "";
    }
    $masque = $mask['fichier'];
    $pos = md5(serialize($variable) . $mask['date_src']);
    $fonction = array('image_masque', func_get_args());
    $image = _image_valeurs_trans($im, "masque-{$masque}-{$pos}", "png", $fonction);
    if (!$image) {
        return "";
    }
    $x_i = $image["largeur"];
    $y_i = $image["hauteur"];
    $im = $image["fichier"];
    $dest = $image["fichier_dest"];
    $creer = $image["creer"];
    // doit-on positionner l'image ?
    $placer = false;
    foreach (array("right", "left", "bottom", "top", "text-align", "vertical-align") as $pl) {
        if (isset($defini[$pl]) and $defini[$pl]) {
            $placer = true;
            break;
        }
    }
    if ($creer) {
        $im_m = $mask["fichier"];
        $x_m = $mask["largeur"];
        $y_m = $mask["hauteur"];
        $im2 = $mask["fonction_imagecreatefrom"]($masque);
        if ($mask["format_source"] == "gif" and function_exists('ImageCopyResampled')) {
            $im2_ = imagecreatetruecolor($x_m, $y_m);
            // Si un GIF est transparent,
            // fabriquer un PNG transparent
            // Conserver la transparence
            if (function_exists("imageAntiAlias")) {
                imageAntiAlias($im2_, true);
            }
            @imagealphablending($im2_, false);
            @imagesavealpha($im2_, true);
            @ImageCopyResampled($im2_, $im2, 0, 0, 0, 0, $x_m, $y_m, $x_m, $y_m);
            imagedestroy($im2);
            $im2 = $im2_;
        }
        if ($placer) {
            // On fabriquer une version "agrandie" du masque,
            // aux dimensions de l'image source
            // et on "installe" le masque dans cette image
            // ainsi: aucun redimensionnement
//.........这里部分代码省略.........
开发者ID:xablen,项目名称:Semaine14_SPIP_test,代码行数:101,代码来源:images_transforme.php

示例6: imageCreateTrueColor

<?php

/* Создание изображения */
// $i = imageCreate(500, 300);
$i = imageCreateTrueColor(500, 300);
/* Подготовка к работе */
imageAntiAlias($i, true);
$red = imageColorAllocate($i, 255, 0, 0);
$white = imageColorAllocate($i, 0xff, 0xff, 0xff);
$black = imageColorAllocate($i, 0, 0, 0);
$green = imageColorAllocate($i, 0, 255, 0);
$blue = imageColorAllocate($i, 0, 0, 255);
$grey = imageColorAllocate($i, 192, 192, 192);
imageFill($i, 0, 0, $grey);
/* Рисуем примитивы */
imageSetPixel($i, 10, 10, $black);
imageLine($i, 20, 20, 280, 180, $red);
imageRectangle($i, 20, 20, 280, 180, $blue);
//array of dots
$points = [120, 120, 100, 200, 300, 200];
imagePolygon($i, $points, 3, $green);
imageEllipse($i, 200, 150, 300, 200, $red);
// imageArc($i, 210, 160, 300, 200, 0, 90, $black);
imageFilledArc($i, 200, 150, 300, 200, 0, 40, $red, IMG_ARC_PIE);
/* Рисуем текст */
imageString($i, 5, 150, 200, 'php7', $black);
imageCharUp($i, 3, 200, 200, 'PHP5', $blue);
imageTtfText($i, 30, 10, 300, 150, $green, 'arial.ttf', 'PHP7');
/* Отдаем изображение */
// header("Content-type: image/gif");
// imageGif($i);
开发者ID:sydorenkovd,项目名称:phpOOPsite.local-train,代码行数:31,代码来源:image_create.php

示例7: image_masque

function image_masque($im, $masque, $pos="") {
	// Passer, en plus de l'image d'origine,
	// une image de "masque": un fichier PNG24 transparent.
	// Le decoupage se fera selon la transparence du "masque",
	// et les couleurs seront eclaircies/foncees selon de couleur du masque.
	// Pour ne pas modifier la couleur, le masque doit etre en gris 50%.
	//
	// Si l'image source est plus grande que le masque, alors cette image est reduite a la taille du masque.
	// Sinon, c'est la taille de l'image source qui est utilisee.
	//
	// $pos est une variable libre, qui permet de passer left=..., right=..., bottom=..., top=...
	// dans ce cas, le pasque est place a ces positions sur l'image d'origine,
	// et evidemment cette image d'origine n'est pas redimensionnee
	// 
	// Positionnement horizontal: text-align=left, right, center
	// Positionnement vertical : vertical-align: top, bottom, middle
	// (les positionnements left, right, top, left sont relativement inutiles, mais coherence avec CSS)
	//
	// Choix du mode de fusion: mode=masque, normal, eclaircir, obscurcir, produit, difference
	// masque: mode par defaut
	// normal: place la nouvelle image par dessus l'ancienne
	// eclaircir: place uniquement les points plus clairs
	// obscurcir: place uniquement les points plus fonc'es
	// produit: multiplie par le masque (points noirs rendent l'image noire, points blancs ne changent rien)
	// difference: remplit avec l'ecart entre les couleurs d'origine et du masque

	$mode = "masque";


	$numargs = func_num_args();
	$arg_list = func_get_args();
	$texte = $arg_list[0];
	for ($i = 1; $i < $numargs; $i++) {
		if ( ($p = strpos($arg_list[$i],"=")) !==false) {
			$nom_variable = substr($arg_list[$i], 0, $p);
			$val_variable = substr($arg_list[$i], $p+1);
			$variable["$nom_variable"] = $val_variable;
			$defini["$nom_variable"] = 1;
		}
	}
	if ($defini["mode"]) $mode = $variable["mode"];

	$masque = find_in_path($masque);
	$pos = md5(serialize($variable).@filemtime($masque));

	$fonction = array('image_masque', func_get_args());
	$image = _image_valeurs_trans($im, "masque-$masque-$pos", "png",$fonction);
	if (!$image) return("");

	$x_i = $image["largeur"];
	$y_i = $image["hauteur"];
	
	$im = $image["fichier"];
	$dest = $image["fichier_dest"];
	
	$creer = $image["creer"];


	if ($defini["right"] OR $defini["left"] OR $defini["bottom"] OR $defini["top"] OR $defini["text-align"] OR $defini["vertical-align"]) {
		$placer = true;
	}
	else $placer = false;

	if ($creer) {
		
		$mask = _image_valeurs_trans($masque,"");
		if (!is_array($mask)) return("");
		$im_m = $mask["fichier"];
		$x_m = $mask["largeur"];
		$y_m = $mask["hauteur"];
	
		$im2 = $mask["fonction_imagecreatefrom"]($masque);
		if ($mask["format_source"] == "gif" AND function_exists('ImageCopyResampled')) { 
			$im2_ = imagecreatetruecolor($x_m, $y_m);
			// Si un GIF est transparent, 
			// fabriquer un PNG transparent  
			// Conserver la transparence 
			if (function_exists("imageAntiAlias")) imageAntiAlias($im2_,true); 
			@imagealphablending($im2_, false); 
			@imagesavealpha($im2_,true); 
			@ImageCopyResampled($im2_, $im2, 0, 0, 0, 0, $x_m, $y_m, $x_m, $y_m);
			imagedestroy($im2);
			$im2 = $im2_;
		}
		
		if ($placer) {
			// On fabriquer une version "agrandie" du masque,
			// aux dimensions de l'image source
			// et on "installe" le masque dans cette image
			// ainsi: aucun redimensionnement
			
			$dx = 0;
			$dy = 0;
			
			if ($defini["right"]) {
				$right = $variable["right"];
				$dx = ($x_i - $x_m) - $right;
			}
			if ($defini["bottom"]) {
				$bottom = $variable["bottom"];
//.........这里部分代码省略.........
开发者ID:rhertzog,项目名称:lcs,代码行数:101,代码来源:images_transforme.php

示例8: NewImgResize

 /**
  * Resize the image
  *
  * Includes function ImageCreateTrueColor and ImageCopyResampled which are available only under GD 2.0.1 or higher !
  *
  * @copyright
  * @author		RolandD
  * @todo		Fix docbloc
  * @see
  * @access 		private
  * @param 		$orig_img
  * @return
  * @since 		3.0
  */
 private function NewImgResize($orig_img)
 {
     $orig_size = getimagesize($this->file);
     $maxX = $this->file_out_width;
     $maxY = $this->file_out_height;
     if ($orig_size[0] < $orig_size[1]) {
         $this->file_out_width = $this->file_out_height * ($orig_size[0] / $orig_size[1]);
         $adjustX = ($maxX - $this->file_out_width) / 2;
         $adjustY = 0;
     } else {
         $this->file_out_height = $this->file_out_width / ($orig_size[0] / $orig_size[1]);
         $adjustX = 0;
         $adjustY = ($maxY - $this->file_out_height) / 2;
     }
     while ($this->file_out_width < 1 || $this->file_out_height < 1) {
         $this->file_out_width *= 2;
         $this->file_out_height *= 2;
     }
     // See if we need to create an image at maximum size
     if ($this->maxSize) {
         if (function_exists("imagecreatetruecolor")) {
             $im_out = imagecreatetruecolor($maxX, $maxY);
         } else {
             $im_out = imagecreate($maxX, $maxY);
         }
         if ($im_out) {
             // Need to image fill just in case image is transparent, don't always want black background
             $bgfill = imagecolorallocate($im_out, $this->bg_red, $this->bg_green, $this->bg_blue);
             if (function_exists("imageAntiAlias")) {
                 imageAntiAlias($im_out, true);
             }
             imagealphablending($im_out, false);
             if (function_exists("imagesavealpha")) {
                 imagesavealpha($im_out, true);
             }
             if (function_exists("imagecolorallocatealpha")) {
                 $transparent = imagecolorallocatealpha($im_out, 255, 255, 255, 127);
             }
             if (function_exists("imagecopyresampled")) {
                 ImageCopyResampled($im_out, $orig_img, $adjustX, $adjustY, 0, 0, $this->file_out_width, $this->file_out_height, $orig_size[0], $orig_size[1]);
             } else {
                 ImageCopyResized($im_out, $orig_img, $adjustX, $adjustY, 0, 0, $this->file_out_width, $this->file_out_height, $orig_size[0], $orig_size[1]);
             }
         } else {
             return false;
         }
     } else {
         if (function_exists("imagecreatetruecolor")) {
             $im_out = ImageCreateTrueColor($this->file_out_width, $this->file_out_height);
         } else {
             $im_out = imagecreate($this->file_out_width, $this->file_out_height);
         }
         if ($im_out) {
             if (function_exists("imageAntiAlias")) {
                 imageAntiAlias($im_out, true);
             }
             imagealphablending($im_out, false);
             if (function_exists("imagesavealpha")) {
                 imagesavealpha($im_out, true);
             }
             if (function_exists("imagecolorallocatealpha")) {
                 $transparent = imagecolorallocatealpha($im_out, 255, 255, 255, 127);
             }
             if (function_exists("imagecopyresampled")) {
                 ImageCopyResampled($im_out, $orig_img, 0, 0, 0, 0, $this->file_out_width, $this->file_out_height, $orig_size[0], $orig_size[1]);
             } else {
                 ImageCopyResized($im_out, $orig_img, 0, 0, 0, 0, $this->file_out_width, $this->file_out_height, $orig_size[0], $orig_size[1]);
             }
         } else {
             return false;
         }
     }
     return $im_out;
 }
开发者ID:srbsnkr,项目名称:sellingonlinemadesimple,代码行数:88,代码来源:images.php

示例9: array

 /**
 *	Maybe adding sharpening with
 *            $sharpenMatrix = array
             (
                 array(-1.2, -1, -1.2),
                 array(-1, 20, -1),
                 array(-1.2, -1, -1.2)
             );
 
             // calculate the sharpen divisor
             $divisor = array_sum(array_map('array_sum', $sharpenMatrix));
 
             $offset = 0;
 
             // apply the matrix
             imageconvolution($img, $sharpenMatrix, $divisor, $offset);
 *
 *	private function - do not call
 *	includes function ImageCreateTrueColor and ImageCopyResampled which are available only under GD 2.0.1 or higher !
 */
 private function NewImgResize($orig_img, $newxsize, $newysize, $filename)
 {
     //getimagesize returns array
     // [0] = width in pixels
     // [1] = height in pixels
     // [2] = type
     // [3] = img tag "width=xx height=xx" values
     $orig_size = getimagesize($filename);
     $newxsize = (int) $newxsize;
     $newysize = (int) $newysize;
     if (empty($newxsize) and empty($newysize)) {
         vmWarn('NewImgResize failed x,y = 0', 'NewImgResize failed x,y = 0');
         return false;
     }
     $maxX = $newxsize;
     $maxY = $newysize;
     if ($orig_size[0] < $orig_size[1]) {
         $newxsize = (int) $newysize * ($orig_size[0] / $orig_size[1]);
         $adjustX = (int) ($maxX - $newxsize) / 2;
         $adjustY = 0;
     } else {
         $newysize = (int) $newxsize / ($orig_size[0] / $orig_size[1]);
         $adjustX = 0;
         $adjustY = (int) ($maxY - $newysize) / 2;
     }
     /* Original code removed to allow for maxSize thumbnails
     		$im_out = ImageCreateTrueColor($newxsize,$newysize);
     		ImageCopyResampled($im_out, $orig_img, 0, 0, 0, 0,
     			$newxsize, $newysize,$orig_size[0], $orig_size[1]);
     		*/
     //	New modification - creates new image at maxSize
     if ($this->maxSize) {
         if (function_exists("imagecreatetruecolor")) {
             $im_out = imagecreatetruecolor($maxX, $maxY);
         } else {
             $im_out = imagecreate($maxX, $maxY);
         }
         // Need to image fill just in case image is transparent, don't always want black background
         $bgfill = imagecolorallocate($im_out, $this->bg_red, $this->bg_green, $this->bg_blue);
         if (function_exists("imageAntiAlias")) {
             imageAntiAlias($im_out, true);
         }
         imagealphablending($im_out, false);
         if (function_exists("imagesavealpha")) {
             imagesavealpha($im_out, true);
         }
         if (function_exists("imagecolorallocatealpha")) {
             $transparent = imagecolorallocatealpha($im_out, 255, 255, 255, 127);
         }
         //imagefill( $im_out, 0,0, $bgfill );
         if (function_exists("imagecopyresampled")) {
             ImageCopyResampled($im_out, $orig_img, $adjustX, $adjustY, 0, 0, $newxsize, $newysize, $orig_size[0], $orig_size[1]);
         } else {
             ImageCopyResized($im_out, $orig_img, $adjustX, $adjustY, 0, 0, $newxsize, $newysize, $orig_size[0], $orig_size[1]);
         }
     } else {
         if (function_exists("imagecreatetruecolor")) {
             $im_out = ImageCreateTrueColor($newxsize, $newysize);
         } else {
             $im_out = imagecreate($newxsize, $newysize);
         }
         if (function_exists("imageAntiAlias")) {
             imageAntiAlias($im_out, true);
         }
         imagealphablending($im_out, false);
         if (function_exists("imagesavealpha")) {
             imagesavealpha($im_out, true);
         }
         if (function_exists("imagecolorallocatealpha")) {
             $transparent = imagecolorallocatealpha($im_out, 255, 255, 255, 127);
         }
         if (function_exists("imagecopyresampled")) {
             ImageCopyResampled($im_out, $orig_img, 0, 0, 0, 0, $newxsize, $newysize, $orig_size[0], $orig_size[1]);
         } else {
             ImageCopyResized($im_out, $orig_img, 0, 0, 0, 0, $newxsize, $newysize, $orig_size[0], $orig_size[1]);
         }
     }
     return $im_out;
 }
开发者ID:denis1001,项目名称:Virtuemart-2-Joomla-3-Bootstrap,代码行数:99,代码来源:img2thumb.php

示例10: imagecreatefromjpeg

<?php

//$img = imageCreateTrueColor(500,300);
$img = imagecreatefromjpeg("images/noise.jpg");
imageAntiAlias($img, true);
//зглаживание
$red = imageColorAllocate($img, 255, 0, 0);
$green = imageColorAllocate($img, 0, 255, 0);
$blue = imageColorAllocate($img, 0, 0, 255);
$white = imageColorAllocate($img, 255, 255, 255);
$black = imageColorAllocate($img, 0, 0, 0);
$silver = imageColorAllocate($img, 192, 192, 192);
/*
imageLine($img,20,20,480,280,$white);
imageLine($img,480,20,20,280,$red);
imageFilledRectangle($img,40,40,80,280,$white);
imageRectangle($img,20,20,80,280,$blue);
$points = array(0,0,100,200,300,200);
imagePolygon($img, $points,3,$green);
imageEllipse($img, 200,150,300,200, $red);
imageFilledEllipse($img, 200,150,300,200, $red);
imageArc($img, 210,160,300,200,0,-60, $blue);
imageFilledArc($img, 210,160,300,200,0,90, $silver, IMG_ARC_NOFILL);
imageString($img, 5, 150, 200, "Hello!", $white);
imageTtfText($img,30,10,200,150,$red,"arial.ttf","Привет!");
*/
imageTtfText($img, 20, 3, 20, 30, $black, "arial.ttf", "Привет");
header('Content-type: image/png');
imagePNG($img);
开发者ID:bz4work,项目名称:spec3,代码行数:29,代码来源:create_image.php

示例11: _image_creer_vignette


//.........这里部分代码省略.........
				exec("$jpegtopnm_command $image | "._PNMSCALE_COMMAND." -width $destWidth | $pnmtojpeg_command > $vignette");
				if (!($s = @filesize($vignette)))
					spip_unlink($vignette);
				if (!@file_exists($vignette)) {
					spip_log("echec netpbm-jpg sur $vignette");
					return;
				}
			} else if ($format == "gif") {
				$giftopnm_command = str_replace("pnmscale", "giftopnm", _PNMSCALE_COMMAND);
				exec("$giftopnm_command $image | "._PNMSCALE_COMMAND." -width $destWidth | $pnmtojpeg_command > $vignette");
				if (!($s = @filesize($vignette)))
					spip_unlink($vignette);
				if (!@file_exists($vignette)) {
					spip_log("echec netpbm-gif sur $vignette");
					return;
				}
			} else if ($format == "png") {
				$pngtopnm_command = str_replace("pnmscale", "pngtopnm", _PNMSCALE_COMMAND);
				exec("$pngtopnm_command $image | "._PNMSCALE_COMMAND." -width $destWidth | $pnmtojpeg_command > $vignette");
				if (!($s = @filesize($vignette)))
					spip_unlink($vignette);
				if (!@file_exists($vignette)) {
					spip_log("echec netpbm-png sur $vignette");
					return;
				}
			}
		}
		// gd ou gd2
		else if ($process == 'gd1' OR $process == 'gd2') {
			if (_IMG_GD_MAX_PIXELS && $srcWidth*$srcHeight>_IMG_GD_MAX_PIXELS){
				spip_log("vignette gd1/gd2 impossible : ".$srcWidth*$srcHeight."pixels");
				return;
			}
			$destFormat = $format_sortie;
			if (!$destFormat) {
				spip_log("pas de format pour $image");
				return;
			}

			$fonction_imagecreatefrom = $valeurs['fonction_imagecreatefrom'];
			if (!function_exists($fonction_imagecreatefrom))
				return '';
			$srcImage = @$fonction_imagecreatefrom($image);
			if (!$srcImage) { 
				spip_log("echec gd1/gd2"); 
				return; 
			} 

			// Initialisation de l'image destination 
				if ($process == 'gd2' AND $destFormat != "gif") 
				$destImage = ImageCreateTrueColor($destWidth, $destHeight); 
			if (!$destImage) 
				$destImage = ImageCreate($destWidth, $destHeight); 

			// Recopie de l'image d'origine avec adaptation de la taille 
			$ok = false; 
			if (($process == 'gd2') AND function_exists('ImageCopyResampled')) { 
				if ($format == "gif") { 
					// Si un GIF est transparent, 
					// fabriquer un PNG transparent  
					$transp = imagecolortransparent($srcImage); 
					if ($transp > 0) $destFormat = "png"; 
				}
				if ($destFormat == "png") { 
					// Conserver la transparence 
					if (function_exists("imageAntiAlias")) imageAntiAlias($destImage,true); 
					@imagealphablending($destImage, false); 
					@imagesavealpha($destImage,true); 
				}
				$ok = @ImageCopyResampled($destImage, $srcImage, 0, 0, 0, 0, $destWidth, $destHeight, $srcWidth, $srcHeight);
			}
			if (!$ok)
				$ok = ImageCopyResized($destImage, $srcImage, 0, 0, 0, 0, $destWidth, $destHeight, $srcWidth, $srcHeight);

			// Sauvegarde de l'image destination
			$valeurs['fichier_dest'] = $vignette = "$destination.$destFormat";
			$valeurs['format_dest'] = $format = $destFormat;
			_image_gd_output($destImage,$valeurs);

			if ($srcImage)
				ImageDestroy($srcImage);
			ImageDestroy($destImage);
		}
	}
	$size = @getimagesize($vignette);
	// Gaffe: en safe mode, pas d'acces a la vignette,
	// donc risque de balancer "width='0'", ce qui masque l'image sous MSIE
	if ($size[0] < 1) $size[0] = $destWidth;
	if ($size[1] < 1) $size[1] = $destHeight;
	
	$retour['width'] = $largeur = $size[0];
	$retour['height'] = $hauteur = $size[1];
	
	$retour['fichier'] = $vignette;
	$retour['format'] = $format;
	$retour['date'] = (file_exists($vignette)) ? filemtime($vignette) : 0;
	
	// renvoyer l'image
	return $retour;
}
开发者ID:rhertzog,项目名称:lcs,代码行数:101,代码来源:filtres_images_lib_mini.php

示例12: resize

 /**
  * Resizes image to maxWidth x maxHeight
  *
  * @param int $maxWidth
  * @param int $maxHeight
  */
 public function resize($maxWidth = 0, $maxHeight = 0)
 {
     $this->maxWidth = $maxWidth;
     $this->maxHeight = $maxHeight;
     $this->calcImageSize($this->currentDimensions['width'], $this->currentDimensions['height']);
     if (function_exists("ImageCreateTrueColor")) {
         if ($this->format == 'PNG') {
             $temp = ImageCreateTrueColor($this->newDimensions['newWidth'], $this->newDimensions['newHeight']);
             // $temp = imagecreatetruecolor($w, $h);
             /* making the new image transparent */
             $background = imagecolorallocate($temp, 0, 0, 0);
             ImageColorTransparent($temp, $background);
             // make the new temp image all transparent
             imagealphablending($temp, false);
             // turn off the alpha blending to keep the alpha channel
             imagesavealpha($temp, true);
             // Save full alpha
             imageAntiAlias($temp, true);
             $this->workingImage = $temp;
         } else {
             $this->workingImage = ImageCreateTrueColor($this->newDimensions['newWidth'], $this->newDimensions['newHeight']);
         }
     } else {
         $this->workingImage = ImageCreate($this->newDimensions['newWidth'], $this->newDimensions['newHeight']);
     }
     ImageCopyResampled($this->workingImage, $this->oldImage, 0, 0, 0, 0, $this->newDimensions['newWidth'], $this->newDimensions['newHeight'], $this->currentDimensions['width'], $this->currentDimensions['height']);
     $this->oldImage = $this->workingImage;
     $this->newImage = $this->workingImage;
     $this->currentDimensions['width'] = $this->newDimensions['newWidth'];
     $this->currentDimensions['height'] = $this->newDimensions['newHeight'];
 }
开发者ID:reeleis,项目名称:ohiocitycycles,代码行数:37,代码来源:thumbnail.inc.php

示例13: osc_gd_resize

function osc_gd_resize($original_image, $dest_image, $dest_width, $dest_height, $force_size = '0')
{
    $img_type = false;
    switch (strtolower(substr(basename($original_image), strrpos(basename($original_image), '.') + 1))) {
        case 'jpg':
        case 'jpeg':
            if (imagetypes() & IMG_JPG) {
                $img_type = 'jpg';
            }
            break;
        case 'gif':
            if (imagetypes() & IMG_GIF) {
                $img_type = 'gif';
            }
            break;
        case 'png':
            if (imagetypes() & IMG_PNG) {
                $img_type = 'png';
            }
            break;
    }
    if ($img_type !== false) {
        list($orig_width, $orig_height) = getimagesize($original_image);
        $width = $dest_width;
        $height = $dest_height;
        $factor = max($orig_width / $width, $orig_height / $height);
        if ($force_size == '1') {
            $width = $dest_width;
        } else {
            $width = round($orig_width / $factor);
            $height = round($orig_height / $factor);
        }
        $im_p = imageCreateTrueColor($dest_width, $dest_height);
        imageAntiAlias($im_p, true);
        imagealphablending($im_p, false);
        imagesavealpha($im_p, true);
        $transparent = imagecolorallocatealpha($im_p, 255, 255, 255, 127);
        for ($x = 0; $x < $dest_width; $x++) {
            for ($y = 0; $y < $dest_height; $y++) {
                imageSetPixel($im_p, $x, $y, $transparent);
            }
        }
        $x = 0;
        $y = 0;
        if ($force_size == '1') {
            $width = round($orig_width * $dest_height / $orig_height);
            if ($width < $dest_width) {
                $x = floor(($dest_width - $width) / 2);
            }
        } else {
            $x = floor(($dest_width - $width) / 2);
            $y = floor(($dest_height - $height) / 2);
        }
        switch ($img_type) {
            case 'jpg':
                $im = imagecreatefromjpeg($original_image);
                break;
            case 'gif':
                $im = imagecreatefromgif($original_image);
                break;
            case 'png':
                $im = imagecreatefrompng($original_image);
                break;
        }
        imagecopyresampled($im_p, $im, $x, $y, 0, 0, $width, $height, $orig_width, $orig_height);
        switch ($img_type) {
            case 'jpg':
                imagejpeg($im_p, $dest_image);
                break;
            case 'gif':
                imagegif($im_p, $dest_image);
                break;
            case 'png':
                imagepng($im_p, $dest_image);
                break;
        }
        imagedestroy($im_p);
        imagedestroy($im);
        @chmod($dest_image, 0777);
    } else {
        return false;
    }
}
开发者ID:Doluci,项目名称:tomatocart,代码行数:83,代码来源:general.php

示例14: round

//Calculate the new size based on the selected area and the minimums
if ($width > $height) {
    $dest_width = $max_width;
    $dest_height = round($max_width * $height / $width);
} else {
    $dest_width = round($max_height * $width / $height);
    $dest_height = $max_height;
}
//we generate a new image object of the size calculated above, using PHP's GD functions
if (!($dest_image = imagecreatetruecolor($dest_width, $dest_height))) {
    die('Could not create new image from source file.');
}
//hack to keep transparency in gif and png
if ($info[2] == IMAGETYPE_GIF || $info[2] == IMAGETYPE_PNG) {
    if ($info[2] == IMAGETYPE_PNG) {
        imageAntiAlias($dest_image, true);
    }
    imagecolortransparent($dest_image, imagecolorallocatealpha($dest_image, 0, 0, 0, 127));
    imagealphablending($dest_image, false);
    imagesavealpha($dest_image, true);
}
/*
this is where we crop the image,
-the first parameter is the destinatation image (not a physical file, but a GD image object)
-second is the source image. Again it's not the physical file but a GD object (which was generated from an image file this time)
-third and fourth params are the X and Y coordinates to paste the copied region in the destination image. In this case we want both of them to be 0,
-fifth and sixth are the X and Y coordinates to start cropping in the source image. So they are pretty much the coordinates we got from UvumiCrop.
-seventh and eighth are the width and height of the destination image, the one calculated right above
-ninth and tenth are the width and height of the cropping region, directly from UvumiCrop again

By just setting $max_width and $max_height above, you should not have to worry about this
开发者ID:Nkelliny,项目名称:MobileDatingApp,代码行数:31,代码来源:download-thumb.php

示例15: _resizeImage

 function _resizeImage($file_path, $newWidth, $newHeight, $dstFolder = '', $type = 'thumbnail', $watermark = '')
 {
     $image = $this->uploadFolder . $file_path;
     if (empty($dstFolder)) {
         $dstFolder = $this->uploadFolder . 'thumbnail_' . $this->thumbnail_y . 'x' . $this->thumbnail_x . DS;
     }
     $watermark_path = '';
     if (hikashop_level(2) && $type == 'image') {
         $config =& hikashop_config();
         $watermark_name = $watermark;
         if (empty($watermark_name) && $watermark_name !== false) {
             $watermark_name = $config->get('watermark', '');
         }
         if (!empty($watermark_name)) {
             $watermark_path = $this->main_uploadFolder . $watermark_name;
             if (!$this->_checkImage($watermark_path)) {
                 $watermark_path = '';
             } else {
                 $wm_extension = strtolower(substr($watermark_path, strrpos($watermark_path, '.') + 1));
                 $watermark = $this->_getImage($watermark_path, $wm_extension);
                 if ($watermark) {
                     if (in_array($wm_extension, array('gif', 'png'))) {
                         imagealphablending($watermark, false);
                         imagesavealpha($watermark, true);
                     }
                 } else {
                     $watermark_path = '';
                 }
             }
         }
     }
     $extension = strtolower(substr($file_path, strrpos($file_path, '.') + 1));
     $img = $this->_getImage($image, $extension);
     if (!$img) {
         return false;
     }
     if (in_array($extension, array('gif', 'png'))) {
         imagealphablending($img, false);
         imagesavealpha($img, true);
     }
     if ($newWidth != $this->width || $newHeight != $this->height) {
         $thumb = ImageCreateTrueColor($newWidth, $newHeight);
         if (in_array($extension, array('gif', 'png'))) {
             $trnprt_indx = imagecolortransparent($img);
             if ($trnprt_indx >= 0) {
                 $trnprt_color = imagecolorsforindex($img, $trnprt_indx);
                 $trnprt_indx = imagecolorallocate($thumb, $trnprt_color['red'], $trnprt_color['green'], $trnprt_color['blue']);
                 imagefill($thumb, 0, 0, $trnprt_indx);
                 imagecolortransparent($thumb, $trnprt_indx);
             } elseif ($extension == 'png') {
                 imagealphablending($thumb, false);
                 $color = imagecolorallocatealpha($thumb, 0, 0, 0, 127);
                 imagefill($thumb, 0, 0, $color);
                 imagesavealpha($thumb, true);
             }
         }
         if (function_exists("imageAntiAlias")) {
             imageAntiAlias($thumb, true);
         }
         if (function_exists("imagecopyresampled")) {
             ImageCopyResampled($thumb, $img, 0, 0, 0, 0, $newWidth, $newHeight, $this->width, $this->height);
         } else {
             ImageCopyResized($thumb, $img, 0, 0, 0, 0, $newWidth, $newHeight, $this->width, $this->height);
         }
     } else {
         $thumb =& $img;
     }
     if (!empty($watermark_path)) {
         list($wm_width, $wm_height) = getimagesize($watermark_path);
         $padding = 3;
         $dest_x = $newWidth - $wm_width - $padding;
         if ($dest_x < 0) {
             $dest_x = 0;
         }
         $dest_y = $newHeight - $wm_height - $padding;
         if ($dest_y < 0) {
             $dest_y = 0;
         }
         $trnprt_color = null;
         if (in_array($extension, array('gif', 'png'))) {
             $trnprt_indx = imagecolortransparent($img);
             if ($trnprt_indx >= 0) {
                 $trnprt_color = imagecolorsforindex($img, $trnprt_indx);
             }
         }
         imagealphablending($thumb, false);
         imagealphablending($watermark, false);
         $this->imagecopymerge_alpha($thumb, $watermark, $dest_x, $dest_y, 0, 0, $wm_width, $wm_height, (int) $config->get('opacity', 0), $trnprt_color);
         imagedestroy($watermark);
     }
     $dest = $dstFolder . $file_path;
     ob_start();
     switch ($extension) {
         case 'gif':
             $status = imagegif($thumb);
             break;
         case 'jpg':
         case 'jpeg':
             $status = imagejpeg($thumb, null, 100);
             break;
//.........这里部分代码省略.........
开发者ID:q0821,项目名称:esportshop,代码行数:101,代码来源:image.php


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