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


PHP ImageSaveAlpha函数代码示例

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


在下文中一共展示了ImageSaveAlpha函数的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: 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

示例3: __construct

 function __construct()
 {
     header('Pragma: public');
     header('Cache-Control: max-age=86400');
     header('Expires: ' . gmdate('D, d M Y H:i:s \\G\\M\\T', time() + 86400));
     header('Content-Type: image/png');
     $this->image = ImageCreateTrueColor(96, 96);
     ImageSaveAlpha($this->image, true);
     ImageFill($this->image, 0, 0, ImageColorAllocateAlpha($this->image, 0, 0, 0, 127));
 }
开发者ID:dream123,项目名称:MapleBit,代码行数:10,代码来源:coordinates.php

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

示例5: CreateGDoutput

 function CreateGDoutput()
 {
     $this->CalculateThumbnailDimensions();
     // Create the GD image (either true-color or 256-color, depending on GD version)
     $this->gdimg_output = phpthumb_functions::ImageCreateFunction($this->thumbnail_width, $this->thumbnail_height);
     // Images that have transparency must have the background filled with the configured 'bg' color
     // otherwise the transparent color will appear as black
     ImageSaveAlpha($this->gdimg_output, true);
     if ($this->is_alpha && phpthumb_functions::gd_version() >= 2) {
         ImageAlphaBlending($this->gdimg_output, false);
         $output_full_alpha = phpthumb_functions::ImageColorAllocateAlphaSafe($this->gdimg_output, 255, 255, 255, 127);
         ImageFilledRectangle($this->gdimg_output, 0, 0, $this->thumbnail_width, $this->thumbnail_height, $output_full_alpha);
     } else {
         $current_transparent_color = ImageColorTransparent($this->gdimg_source);
         if ($this->bg || @$current_transparent_color >= 0) {
             $this->config_background_hexcolor = $this->bg ? $this->bg : $this->config_background_hexcolor;
             if (!phpthumb_functions::IsHexColor($this->config_background_hexcolor)) {
                 return $this->ErrorImage('Invalid hex color string "' . $this->config_background_hexcolor . '" for parameter "bg"');
             }
             $background_color = phpthumb_functions::ImageHexColorAllocate($this->gdimg_output, $this->config_background_hexcolor);
             ImageFilledRectangle($this->gdimg_output, 0, 0, $this->thumbnail_width, $this->thumbnail_height, $background_color);
         }
     }
     $this->DebugMessage('CreateGDoutput() returning canvas "' . $this->thumbnail_width . 'x' . $this->thumbnail_height . '"', __FILE__, __LINE__);
     return true;
 }
开发者ID:notzen,项目名称:exponent-cms,代码行数:26,代码来源:phpthumb.class.php

示例6: ImageSY

    $yi = ImageSY($image);
    // find the size of the text
    $box = ImageFTBBox($size, $angle, $font, $text, $extrainfo);
    $xr = abs(max($box[2], $box[4]));
    $yr = abs(max($box[5], $box[7]));
    // compute centering
    $x = intval(($xi - $xr) / 2);
    $y = intval(($yi + $yr) / 2);
    return array($x, $y);
}
$_GET['text'] = 'I <3 PHP!';
// Configuration settings
$image = ImageCreateFromPNG(__DIR__ . '/button.png');
$text = $_GET['text'];
$font = '/Library/Fonts/Hei.ttf';
$size = 24;
$color = 0x0;
$angle = 0;
// Print-centered text
list($x, $y) = ImageFTCenter($image, $size, $angle, $font, $text);
ImageFTText($image, $size, $angle, $x, $y, $color, $font, $text);
// Preserve Transparency
ImageColorTransparent($image, ImageColorAllocateAlpha($image, 0, 0, 0, 127));
ImageAlphaBlending($image, false);
ImageSaveAlpha($image, true);
// Send image
header('Content-type: image/png');
ImagePNG($image);
// Clean up
ImagePSFreeFont($font);
ImageDestroy($image);
开发者ID:zmwebdev,项目名称:PHPcookbook-code-3ed,代码行数:31,代码来源:dynamic1.php

示例7: createThumb

 /**
  * Create a thumbnail image
  * @param  string  $fileName   The image filename
  */
 function createThumb($fileName, $filePath)
 {
     //copy image
     $oldFile = $this->mediaPath . $filePath . $fileName;
     $newFile = $this->mediaPath . "thumbs/" . $fileName;
     $arrSettings = $this->getSettings();
     $arrInfo = getimagesize($oldFile);
     //ermittelt die Größe des Bildes
     $setSize = $arrSettings['thumbSize']['value'];
     $strType = $arrInfo[2];
     //type des Bildes
     if ($arrInfo[0] >= $setSize || $arrInfo[1] >= $setSize) {
         if ($arrInfo[0] <= $arrInfo[1]) {
             $intFactor = $arrInfo[1] / $setSize;
             $intHeight = $setSize;
             $intWidth = $arrInfo[0] / $intFactor;
         } else {
             $intFactor = $arrInfo[0] / $setSize;
             $intResult = $arrInfo[1] / $intFactor;
             if ($intResult > $setSize) {
                 $intHeight = $setSize;
                 $intWidth = $arrInfo[0] / $intFactor;
             } else {
                 $intWidth = $setSize;
                 $intHeight = $arrInfo[1] / $intFactor;
             }
         }
     } else {
         $intWidth = $arrInfo[0];
         $intHeight = $arrInfo[1];
     }
     if (imagetypes() & IMG_GIF) {
         $boolGifEnabled = true;
     }
     if (imagetypes() & IMG_JPG) {
         $boolJpgEnabled = true;
     }
     if (imagetypes() & IMG_PNG) {
         $boolPngEnabled = true;
     }
     @touch($newFile);
     switch ($strType) {
         case 1:
             //GIF
             if ($boolGifEnabled) {
                 $handleImage1 = ImageCreateFromGif($oldFile);
                 $handleImage2 = @ImageCreateTrueColor($intWidth, $intHeight);
                 ImageCopyResampled($handleImage2, $handleImage1, 0, 0, 0, 0, $intWidth, $intHeight, $arrInfo[0], $arrInfo[1]);
                 ImageGif($handleImage2, $newFile);
                 ImageDestroy($handleImage1);
                 ImageDestroy($handleImage2);
             }
             break;
         case 2:
             //JPG
             if ($boolJpgEnabled) {
                 $handleImage1 = ImageCreateFromJpeg($oldFile);
                 $handleImage2 = @ImageCreateTrueColor($intWidth, $intHeight);
                 ImageCopyResampled($handleImage2, $handleImage1, 0, 0, 0, 0, $intWidth, $intHeight, $arrInfo[0], $arrInfo[1]);
                 ImageJpeg($handleImage2, $newFile, 95);
                 ImageDestroy($handleImage1);
                 ImageDestroy($handleImage2);
             }
             break;
         case 3:
             //PNG
             if ($boolPngEnabled) {
                 $handleImage1 = ImageCreateFromPNG($oldFile);
                 ImageAlphaBlending($handleImage1, true);
                 ImageSaveAlpha($handleImage1, true);
                 $handleImage2 = @ImageCreateTrueColor($intWidth, $intHeight);
                 ImageCopyResampled($handleImage2, $handleImage1, 0, 0, 0, 0, $intWidth, $intHeight, $arrInfo[0], $arrInfo[1]);
                 ImagePNG($handleImage2, $newFile);
                 ImageDestroy($handleImage1);
                 ImageDestroy($handleImage2);
             }
             break;
     }
 }
开发者ID:nahakiole,项目名称:cloudrexx,代码行数:83,代码来源:DirectoryLibrary.class.php

示例8: elseif

} 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);
    }
    $cleanedupurl = phpthumb_functions::CleanUpURLencoding($phpThumb->src);
开发者ID:CrazyBobik,项目名称:allotaxi.test,代码行数:31,代码来源:phpThumb.php

示例9: rotate

 public function rotate($value = 90, $bgColor = 'transparent')
 {
     # Author:     Jarrod Oberto
     # Date:       07-05-2011
     # Purpose:    Rotate image
     # Param in:   (mixed) $degrees: (int) number of degress to rotate image
     #               (str) param "left": rotate left
     #               (str) param "right": rotate right
     #               (str) param "upside": upside-down image
     # Param out:
     # Reference:
     # Notes:    The default direction of imageRotate() is counter clockwise.
     #
     if ($this->imageResized) {
         if (is_integer($value)) {
             $degrees = $value;
         }
         // *** Convert color
         $rgbArray = $this->formatColor($bgColor);
         $r = $rgbArray['r'];
         $g = $rgbArray['g'];
         $b = $rgbArray['b'];
         if (isset($rgbArray['a'])) {
             $a = $rgbArray['a'];
         }
         if (is_string($value)) {
             $value = strtolower($value);
             switch ($value) {
                 case 'left':
                     $degrees = 90;
                     break;
                 case 'right':
                     $degrees = 270;
                     break;
                 case 'upside':
                     $degrees = 180;
                     break;
                 default:
                     break;
             }
         }
         // *** The default direction of imageRotate() is counter clockwise
         //   * This makes it clockwise
         $degrees = 360 - $degrees;
         // *** Create background color
         $bg = ImageColorAllocateAlpha($this->imageResized, $r, $g, $b, $a);
         // *** Fill with background
         ImageFill($this->imageResized, 0, 0, $bg);
         // *** Rotate
         $this->imageResized = imagerotate($this->imageResized, $degrees, $bg);
         // Rotate 45 degrees and allocated the transparent colour as the one to make transparent (obviously)
         // Ensure alpha transparency
         ImageSaveAlpha($this->imageResized, true);
     }
 }
开发者ID:visualweber,项目名称:appzf1,代码行数:55,代码来源:imageLib.php

示例10: ImageResize

function ImageResize($image, $paras){
	$xcount = ImageSX($image);
	$ycount = ImageSY($image);
	
	if ($paras["width"]){
		$newwidth = $paras["width"];
	}
	
	if ($paras["height"]){
		$newheight = $paras["height"];
	}
	
	if ($newwidth && !$newheight){
		$newheight = round($ycount / ($xcount / $newwidth));
	}
	
	if ($newheight && !$newwidth){
		$newwidth = round($xcount / ($ycount / $newheight));
	}
	
	$newimage = ImageCreateTrueColor($newwidth, $newheight);
	ImageAlphaBlending($newimage, false);
	ImageSaveAlpha($newimage, true);
	
	ImageCopyResampled($newimage, $image, 0, 0, 0, 0, $newwidth, $newheight, $xcount, $ycount);
	return $newimage;
}
开发者ID:kaspernj,项目名称:knjphpfw,代码行数:27,代码来源:image.php

示例11: reduire_image


//.........这里部分代码省略.........
            $img->setImageFormat("png");
            $img->setCompression(Imagick::COMPRESSION_LZW);
            $img->setCompressionQuality(90);
            $contenu_vignette = $img->getImageBlob();
        } catch (Exception $ex) {
            $error = true;
        }
        unlink($fichier_tmp);
    }
    if ($error) {
        $size = @getimagesize($bidon);
        /*   ".gif"=>"1",
        	         ".jpg"=>"2",
        	         ".jpeg"=>"2",
        	         ".png"=>"3",
        	         ".swf"=>"4",
        	         ".psd"=>"5",
        	         ".bmp"=>"6");
        		*/
        switch ($size[2]) {
            case 1:
                $src_img = imagecreatefromgif($bidon);
                break;
            case 2:
                $src_img = imagecreatefromjpeg($bidon);
                break;
            case 3:
                $src_img = imagecreatefrompng($bidon);
                break;
            case 6:
                $src_img = imagecreatefromwbmp($bidon);
                break;
            default:
                break;
        }
        $erreur_vignette = 0;
        if ($src_img) {
            $rs = $pmb_vignette_x / $pmb_vignette_y;
            $taillex = imagesx($src_img);
            $tailley = imagesy($src_img);
            if (!$taillex || !$tailley) {
                return "";
            }
            if ($taillex > $pmb_vignette_x || $tailley > $pmb_vignette_y) {
                $r = $taillex / $tailley;
                if ($r < 1 && $rs < 1) {
                    //Si x plus petit que y et taille finale portrait
                    //Si le format final est plus large en proportion
                    if ($rs > $r) {
                        $new_h = $pmb_vignette_y;
                        $new_w = $new_h * $r;
                    } else {
                        $new_w = $pmb_vignette_x;
                        $new_h = $new_w / $r;
                    }
                } else {
                    if ($r < 1 && $rs >= 1) {
                        //Si x plus petit que y et taille finale paysage
                        $new_h = $pmb_vignette_y;
                        $new_w = $new_h * $r;
                    } else {
                        if ($r > 1 && $rs < 1) {
                            //Si x plus grand que y et taille finale portrait
                            $new_w = $pmb_vignette_x;
                            $new_h = $new_w / $r;
                        } else {
                            //Si x plus grand que y et taille finale paysage
                            if ($rs < $r) {
                                $new_w = $pmb_vignette_x;
                                $new_h = $new_w / $r;
                            } else {
                                $new_h = $pmb_vignette_y;
                                $new_w = $new_h * $r;
                            }
                        }
                    }
                }
            } else {
                $new_h = $tailley;
                $new_w = $taillex;
            }
            $dst_img = imagecreatetruecolor($pmb_vignette_x, $pmb_vignette_y);
            ImageSaveAlpha($dst_img, true);
            ImageAlphaBlending($dst_img, false);
            imagefilledrectangle($dst_img, 0, 0, $pmb_vignette_x, $pmb_vignette_y, imagecolorallocatealpha($dst_img, 0, 0, 0, 127));
            imagecopyresized($dst_img, $src_img, round(($pmb_vignette_x - $new_w) / 2), round(($pmb_vignette_y - $new_h) / 2), 0, 0, $new_w, $new_h, ImageSX($src_img), ImageSY($src_img));
            imagepng($dst_img, "{$base_path}/temp/" . SESSid);
            $fp = fopen("{$base_path}/temp/" . SESSid, "r");
            $contenu_vignette = fread($fp, filesize("{$base_path}/temp/" . SESSid));
            if (!$fp || $contenu_vignette == "") {
                $erreur_vignette++;
            }
            fclose($fp);
            unlink("{$base_path}/temp/" . SESSid);
        } else {
            $contenu_vignette = '';
        }
    }
    return $contenu_vignette;
}
开发者ID:noble82,项目名称:proyectos-ULS,代码行数:101,代码来源:explnum.inc.php

示例12: imagecreatefromstring

function &reduire_image_middle(&$data)
{
    global $opac_photo_mean_size_x;
    global $opac_photo_mean_size_y;
    global $opac_photo_watermark;
    global $opac_photo_watermark_transparency;
    if ($opac_photo_watermark_transparency == "") {
        $opac_photo_watermark_transparency = 50;
    }
    $src_img = imagecreatefromstring($data);
    if ($src_img) {
        $photo_mean_size_x = imagesx($src_img);
        $photo_mean_size_y = imagesy($src_img);
    } else {
        $photo_mean_size_x = 200;
        $photo_mean_size_y = 200;
    }
    if ($opac_photo_mean_size_x) {
        $photo_mean_size_x = $opac_photo_mean_size_x;
    }
    if ($opac_photo_mean_size_y) {
        $photo_mean_size_y = $opac_photo_mean_size_y;
    }
    if ($opac_photo_watermark) {
        $size = @getimagesize("images/" . $opac_photo_watermark);
        /*   ".gif"=>"1",
        		                   ".jpg"=>"2",
        		                   ".jpeg"=>"2",
        		                   ".png"=>"3",
        		                   ".swf"=>"4",
        		                   ".psd"=>"5",
        		                   ".bmp"=>"6");
        		*/
        switch ($size[2]) {
            case 1:
                $wat_img = imagecreatefromgif("images/" . $opac_photo_watermark);
                break;
            case 2:
                $wat_img = imagecreatefromjpeg("images/" . $opac_photo_watermark);
                break;
            case 3:
                $wat_img = imagecreatefrompng("images/" . $opac_photo_watermark);
                break;
            case 6:
                $wat_img = imagecreatefromwbmp("images/" . $opac_photo_watermark);
                break;
            default:
                $wat_img = "";
                break;
        }
    }
    $erreur_vignette = 0;
    if ($src_img) {
        $rs = $photo_mean_size_x / $photo_mean_size_y;
        $taillex = imagesx($src_img);
        $tailley = imagesy($src_img);
        if (!$taillex || !$tailley) {
            return "";
        }
        if ($taillex > $photo_mean_size_x || $tailley > $photo_mean_size_y) {
            $r = $taillex / $tailley;
            if ($r < 1 && $rs < 1) {
                //Si x plus petit que y et taille finale portrait
                //Si le format final est plus large en proportion
                if ($rs > $r) {
                    $new_h = $photo_mean_size_y;
                    $new_w = $new_h * $r;
                } else {
                    $new_w = $photo_mean_size_x;
                    $new_h = $new_w / $r;
                }
            } else {
                if ($r < 1 && $rs >= 1) {
                    //Si x plus petit que y et taille finale paysage
                    $new_h = $photo_mean_size_y;
                    $new_w = $new_h * $r;
                } else {
                    if ($r > 1 && $rs < 1) {
                        //Si x plus grand que y et taille finale portrait
                        $new_w = $photo_mean_size_x;
                        $new_h = $new_w / $r;
                    } else {
                        //Si x plus grand que y et taille finale paysage
                        if ($rs < $r) {
                            $new_w = $photo_mean_size_x;
                            $new_h = $new_w / $r;
                        } else {
                            $new_h = $photo_mean_size_y;
                            $new_w = $new_h * $r;
                        }
                    }
                }
            }
        } else {
            $new_h = $tailley;
            $new_w = $taillex;
        }
        $dst_img = imagecreatetruecolor($photo_mean_size_x, $photo_mean_size_y);
        ImageSaveAlpha($dst_img, true);
        ImageAlphaBlending($dst_img, false);
//.........这里部分代码省略.........
开发者ID:hogsim,项目名称:PMB,代码行数:101,代码来源:explnum.inc.php

示例13: Image

function Image($image, $crop = null, $size = null, $user)
{
    $image = ImageCreateFromString(file_get_contents($image));
    if (is_resource($image) === true) {
        $x = 0;
        $y = 0;
        $width = imagesx($image);
        $height = imagesy($image);
        /*
        CROP (Aspect Ratio) Section
        */
        if (is_null($crop) === true) {
            $crop = array($width, $height);
        } else {
            $crop = array_filter(explode(':', $crop));
            if (empty($crop) === true) {
                $crop = array($width, $height);
            } else {
                if (empty($crop[0]) === true || is_numeric($crop[0]) === false) {
                    $crop[0] = $crop[1];
                } else {
                    if (empty($crop[1]) === true || is_numeric($crop[1]) === false) {
                        $crop[1] = $crop[0];
                    }
                }
            }
            $ratio = array(0 => $width / $height, 1 => $crop[0] / $crop[1]);
            if ($ratio[0] > $ratio[1]) {
                $width = $height * $ratio[1];
                $x = (imagesx($image) - $width) / 2;
            } else {
                if ($ratio[0] < $ratio[1]) {
                    $height = $width / $ratio[1];
                    $y = (imagesy($image) - $height) / 2;
                }
            }
        }
        /*
        Resize Section
        */
        if (is_null($size) === true) {
            $size = array($width, $height);
        } else {
            $size = array_filter(explode('x', $size));
            if (empty($size) === true) {
                $size = array(imagesx($image), imagesy($image));
            } else {
                if (empty($size[0]) === true || is_numeric($size[0]) === false) {
                    $size[0] = round($size[1] * $width / $height);
                } else {
                    if (empty($size[1]) === true || is_numeric($size[1]) === false) {
                        $size[1] = round($size[0] * $height / $width);
                    }
                }
            }
        }
        $result = ImageCreateTrueColor($size[0], $size[1]);
        if (is_resource($result) === true) {
            ImageSaveAlpha($result, true);
            ImageAlphaBlending($result, true);
            ImageFill($result, 0, 0, ImageColorAllocate($result, 255, 255, 255));
            ImageCopyResampled($result, $image, 0, 0, $x, $y, $size[0], $size[1], $width, $height);
            ImageInterlace($result, true);
            $file1 = $result;
            $file2 = 'sim33.png';
            // Second image (the overlay)
            $overlay = imagecreatefrompng($file2);
            // We need to know the width and height of the overlay
            list($widthx, $heightx, $type, $attr) = getimagesize($file2);
            // Apply the overlay
            imagecopy($file1, $overlay, 0, 0, 0, 0, $widthx, $heightx);
            imagedestroy($overlay);
            // Output the results
            imagejpeg($file1, 'pics/avatar-' . $user . '.jpg', 90);
            echo '<img src="pics/avatar-' . $user . '.jpg" alt="">';
            imagedestroy($file1);
            //ImageJPEG($result, null, 90);
        }
    }
    return false;
}
开发者ID:andrei-popa,项目名称:XFactor_FBApp,代码行数:81,代码来源:index.php

示例14: resizeToDisplay

 function resizeToDisplay()
 {
     $src_img = imagecreatefromstring($this->driver->openCurrentDoc());
     if ($src_img) {
         $photo_mean_size_x = imagesx($src_img);
         $photo_mean_size_y = imagesy($src_img);
     } else {
         $photo_mean_size_x = 200;
         $photo_mean_size_y = 200;
     }
     $maxX = $this->parameters["size_x"];
     $maxY = $this->parameters["size_y"];
     if ($maxX) {
         $photo_mean_size_x = $maxX;
     }
     if ($maxY) {
         $photo_mean_size_y = $maxY;
     }
     if ($src_img) {
         $rs = $photo_mean_size_x / $photo_mean_size_y;
         $taillex = imagesx($src_img);
         $tailley = imagesy($src_img);
         if (!$taillex || !$tailley) {
             return "";
         }
         if ($taillex > $photo_mean_size_x || $tailley > $photo_mean_size_y) {
             $r = $taillex / $tailley;
             if ($r < 1 && $rs < 1) {
                 //Si x plus petit que y et taille finale portrait
                 //Si le format final est plus large en proportion
                 if ($rs > $r) {
                     $new_h = $photo_mean_size_y;
                     $new_w = $new_h * $r;
                 } else {
                     $new_w = $photo_mean_size_x;
                     $new_h = $new_w / $r;
                 }
             } else {
                 if ($r < 1 && $rs >= 1) {
                     //Si x plus petit que y et taille finale paysage
                     $new_h = $photo_mean_size_y;
                     $new_w = $new_h * $r;
                 } else {
                     if ($r > 1 && $rs < 1) {
                         //Si x plus grand que y et taille finale portrait
                         $new_w = $photo_mean_size_x;
                         $new_h = $new_w / $r;
                     } else {
                         //Si x plus grand que y et taille finale paysage
                         if ($rs < $r) {
                             $new_w = $photo_mean_size_x;
                             $new_h = $new_w / $r;
                         } else {
                             $new_h = $photo_mean_size_y;
                             $new_w = $new_h * $r;
                         }
                     }
                 }
             }
         } else {
             $new_h = $tailley;
             $new_w = $taillex;
         }
         $dst_img = imagecreatetruecolor($new_w, $new_h);
         ImageSaveAlpha($dst_img, true);
         ImageAlphaBlending($dst_img, false);
         imagefilledrectangle($dst_img, 0, 0, $photo_mean_size_x, $photo_mean_size_y, imagecolorallocatealpha($dst_img, 0, 0, 0, 127));
         imagecopyresized($dst_img, $src_img, 0, 0, 0, 0, $new_w, $new_h, ImageSX($src_img), ImageSY($src_img));
         $watermark = $this->driver->getUrlImage($this->parameters['watermark']);
         if ($watermark != "") {
             $size = @getimagesize($watermark);
             switch ($size[2]) {
                 case 1:
                     $wat_img = imagecreatefromgif($watermark);
                     break;
                 case 2:
                     $wat_img = imagecreatefromjpeg($watermark);
                     break;
                 case 3:
                     $wat_img = imagecreatefrompng($watermark);
                     break;
                 case 6:
                     $wat_img = imagecreatefromwbmp($watermark);
                     break;
                 default:
                     $wat_img = "";
                     break;
             }
             if ($wat_img) {
                 $wr_img = imagecreatetruecolor($new_w, $new_h);
                 imagecolortransparent($wr_img, imagecolorallocatealpha($wr_img, 0, 0, 0, 127));
                 ImageSaveAlpha($wr_img, true);
                 ImageAlphaBlending($wr_img, false);
                 imagefilledrectangle($wr_img, 0, 0, $new_w, $new_h, imagecolorallocatealpha($wr_img, 0, 0, 0, 127));
                 imagecopyresized($wr_img, $wat_img, 0, 0, 0, 0, $new_w, $new_h, ImageSX($wat_img), ImageSY($wat_img));
                 imagecopymerge($dst_img, $wr_img, 0, 0, 0, 0, $new_w, $new_h, $this->parameters['transparence']);
             }
         }
         imagepng($dst_img);
     }
//.........这里部分代码省略.........
开发者ID:bouchra012,项目名称:PMB,代码行数:101,代码来源:images.class.php

示例15: ApplyMask

function ApplyMask(&$gdimg_mask, &$gdimg_image)
{
    if (gd_version() < 2) {
        $DebugMessage = 'Skipping ApplyMask() because gd_version is "' . gd_version() . '"' . __FILE__ . __LINE__;
        return false;
    }
    if (version_compare_replacement(phpversion(), '4.3.2', '>=')) {
        $DebugMessage = 'Using alpha ApplyMask() technique' . __FILE__ . __LINE__;
        if ($gdimg_mask_resized = ImageCreateTrueColor(ImageSX($gdimg_image), ImageSY($gdimg_image))) {
            ImageCopyResampled($gdimg_mask_resized, $gdimg_mask, 0, 0, 0, 0, ImageSX($gdimg_image), ImageSY($gdimg_image), ImageSX($gdimg_mask), ImageSY($gdimg_mask));
            if ($gdimg_mask_blendtemp = ImageCreateTrueColor(ImageSX($gdimg_image), ImageSY($gdimg_image))) {
                $color_background = ImageColorAllocate($gdimg_mask_blendtemp, 0, 0, 0);
                ImageFilledRectangle($gdimg_mask_blendtemp, 0, 0, ImageSX($gdimg_mask_blendtemp), ImageSY($gdimg_mask_blendtemp), $color_background);
                ImageAlphaBlending($gdimg_mask_blendtemp, false);
                ImageSaveAlpha($gdimg_mask_blendtemp, true);
                for ($x = 0; $x < ImageSX($gdimg_image); $x++) {
                    for ($y = 0; $y < ImageSY($gdimg_image); $y++) {
                        //$RealPixel = phpthumb_functions::GetPixelColor($gdimg_mask_blendtemp, $x, $y);
                        $RealPixel = GetPixelColor($gdimg_image, $x, $y);
                        $MaskPixel = GrayscalePixel(GetPixelColor($gdimg_mask_resized, $x, $y));
                        $MaskAlpha = 127 - floor($MaskPixel['red'] / 2) * (1 - $RealPixel['alpha'] / 127);
                        $newcolor = ImageColorAllocateAlphaSafe($gdimg_mask_blendtemp, $RealPixel['red'], $RealPixel['green'], $RealPixel['blue'], $MaskAlpha);
                        ImageSetPixel($gdimg_mask_blendtemp, $x, $y, $newcolor);
                    }
                }
                ImageAlphaBlending($gdimg_image, false);
                ImageSaveAlpha($gdimg_image, true);
                ImageCopy($gdimg_image, $gdimg_mask_blendtemp, 0, 0, 0, 0, ImageSX($gdimg_mask_blendtemp), ImageSY($gdimg_mask_blendtemp));
                ImageDestroy($gdimg_mask_blendtemp);
            } else {
                $DebugMessage = 'ImageCreateFunction() failed' . __FILE__ . __LINE__;
            }
            ImageDestroy($gdimg_mask_resized);
        } else {
            $DebugMessage = 'ImageCreateFunction() failed' . __FILE__ . __LINE__;
        }
    } else {
        // alpha merging requires PHP v4.3.2+
        $DebugMessage = 'Skipping ApplyMask() technique because PHP is v"' . phpversion() . '"' . __FILE__ . __LINE__;
    }
    return true;
}
开发者ID:emoksha,项目名称:VoteReport-Lebanon,代码行数:42,代码来源:post-thumb-image-editor.php


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