PHP GD形象问题

我试图代码的东西,我可以在彼此的顶部覆盖图像,并让它们输出1个图像。 此外,我有它,我可以移动图像20像素以上和10 PX下来之一。 我曾做过的一切,并成立了我多么希望,但唯一的问题是,当我移动图像向右之一它显示在左边有一个黑点,我如何得到这一切是透明的。 即使当图像被移动?

<?php $layers = array(); $shiftx = array(); $shifty = array(); $wid = array(); $hei = array(); $layers[] = imagecreatefrompng("egg.png"); $shiftx[] = "0"; $shifty[] = "0"; $wid[] = "75"; $hei[] = "75"; $layers[] = imagecreatefrompng("fedora.png");//Top Layer $shiftx[] = "-20"; $shifty[] = "0"; $wid[] = "56"; $hei[] = "56"; $image = imagecreatetruecolor(100, 100); $transparent = imagecolorallocatealpha($image, 255, 255, 255, 127); imagefill($image, 0, 0, $transparent); //Will merge the layers into one image// for ($i = 0; $i < count($layers); $i++) { $y=$shifty[$i]; $x=$shiftx[$i]; $w=$wid[$i]-$shiftx[$i]; $h=$hei[$i]-$shifty[$i]; imagecopy($image, $layers[$i], 0, 0, $x, $y, $w, $h); } //Everything is now done, except for the image output. We will do this now.// header('Content-type: image/png'); imagealphablending($image, false); imagesavealpha($image, true); imagepng($image); imagedestroy($image);

?>

--------------解决方案-------------

尝试是这样的:

if(($this->image_type == 1) || ($this->image_type == 3)){
imagealphablending($new_image, false);
imagesavealpha($new_image,true);
$transparent = imagecolorallocatealpha($new_image, 255, 255, 255, 127);
imagefilledrectangle($new_image, 0, 0, $width, $height, $transparent);
}

这是从我的CakePHP的图像minipulation类。 这perserves PNG和GIF透明度。 我不会建议复制这个确切的,但只是把玉在正确的轨道上

PS:请注意,这 - $>图像和$ new_image是加载的图像。

它装载这样的:

function load($filename) {
$image_info = getimagesize($filename);
$this->image_type = $image_info[2];
if( $this->image_type == IMAGETYPE_JPEG ) {
$this->image_type == 2;
$this->image_ext = 'jpg';
$this->image = imagecreatefromjpeg($filename);
} elseif( $this->image_type == IMAGETYPE_GIF ) {
$this->image_type == 3;
$this->image_ext = 'gif';
$this->image = imagecreatefromgif($filename);
} elseif( $this->image_type == IMAGETYPE_PNG ) {
$this->image_type = 1;
$this->image_ext = 'png';
$this->image = imagecreatefrompng($filename);
}
}

PSS如果youre要一个水印..这是我做了什么:

function waterMark($image, $horizontal='right', $vertical='bottom'){
// Get extension
$extension = $this->__getExtension($image);

// Image info
list($width, $height, $type) = getimagesize($image);

// Get image resource
$watermark = $this->__getImageResource($image, $extension);

// Resource width and height
$image_width = imagesx($this->image);
$image_height = imagesy($this->image);

// Calculate positions
$position_x = $horizontal;
$position_y = $vertical;
switch($position_x){
case "left":
$position_x = 0;
break;
case "center":
$position_x = ceil($image_width/2) - floor($width/2);
break;
case "right":
$position_x = $image_width - $width;
break;
}
switch($position_y){
case "top":
$position_y = 0;
break;
case "center":
$position_y = ceil($image_height/2) - floor($height/2);
break;
case "bottom":
$position_y = $image_height - $height;
break;
}

$extension = $this->__getExtension($image);
if($extension == "png"){
$this->__imagecopymergePng($this->image, $watermark, $position_x, $position_y, 0, 0, $width, $height, 100);
}else{
imagecopymerge($this->image, $watermark, $position_x, $position_y, 0, 0, $width, $height, 100);
}

// Destroy watermark
imagedestroy($watermark);
}

分类:php 时间:2015-03-15 人气:0
本文关键词: PHP
分享到:

相关文章

Copyright (C) 55228885.com, All Rights Reserved.

55228885 版权所有 京ICP备15002868号

processed in 0.298 (s). 9 q(s)