Ir para conteúdo

Arquivado

Este tópico foi arquivado e está fechado para novas respostas.

vdepizzol

Marca d'água com png transparente

Recommended Posts

oi,ao usar imagecopymerge para colocar a logomarca do meu site no canto das fotos, a logo.png (com transparencia alpha) não ficou transparente, o que era meio transparente ficou preto...Tentei usar as funções imagealphablending e imagealpha mas nao funcionou...alguém sabe como consertar?

Compartilhar este post


Link para o post
Compartilhar em outros sites

O código é esse daí:

 

PHP

[*]class thumbnail

[*]{

[*] var $img;

[*] var $logo;

[*]

[*] function thumbnail($imgfile)

[*] {

[*] $this->logo['use_logo'] = false;

[*] //detect image format

[*] $this->img['format'] = explode(".", strtoupper($imgfile));

[*] $this->img['format'] = $this->img['format'][count($this->img['format])-1];

[*] if ($this->img["format"]=="JPG" || $this->img["format"]=="JPEG") {

[*] //JPEG

[*] $this->img["format"]="JPEG";

[*] $this->img["src"] = imagecreatefromjpeg ($imgfile);

[*] } elseif ($this->img["format"]=="PNG") {

[*] //PNG

[*] $this->img["format"]="PNG";

[*] $this->img["src"] = imagecreatefrompng ($imgfile);

[*] } elseif ($this->img["format"]=="GIF") {

[*] //GIF

[*] $this->img["format"]="GIF";

[*] $this->img["src"] = imagecreatefromgif ($imgfile);

[*] } elseif ($this->img["format"]=="WBMP") {

[*] //WBMP

[*] $this->img["format"]="WBMP";

[*] $this->img["src"] = imagecreatefromwbmp ($imgfile);

[*] } else {

[*] //DEFAULT

[*] echo "Arquivo não suportado";

[*] exit();

[*] }

[*] @$this->img["lebar"] = imagesx($this->img["src"]);

[*] @$this->img["tinggi"] = imagesy($this->img["src"]);

[*] //default quality jpeg

[*] $this->img["quality"]=75;

[*] imagesavealpha($this->img['src'], true);

[*] imagealphablending($this->img['src'], false)

[*]

[*]

[*] }

[*]

[*] function size_height($size=100)

[*] {

[*] //height

[*] $this->img["tinggi_thumb"]=$size;

[*] @$this->img["lebar_thumb"] = ($this->img["tinggi_thumb"]/$this->img["tinggi"])*$this->img["lebar"];

[*] }

[*]

[*] function size_width($size=100)

[*] {

[*] //width

[*] $this->img["lebar_thumb"]=$size;

[*] @$this->img["tinggi_thumb"] = ($this->img["lebar_thumb"]/$this->img["lebar"])*$this->img["tinggi"];

[*] }

[*]

[*] function size_auto($size=100)

[*] {

[*] //size

[*] if ($this->img["lebar"]>=$this->img["tinggi"]) {

[*] $this->img["lebar_thumb"]=$size;

[*] @$this->img["tinggi_thumb"] = ($this->img["lebar_thumb"]/$this->img["lebar"])*$this->img["tinggi"];

[*] } else {

[*] $this->img["tinggi_thumb"]=$size;

[*] @$this->img["lebar_thumb"] = ($this->img["tinggi_thumb"]/$this->img["tinggi"])*$this->img["lebar"];

[*]  }

[*] }

[*]

[*] function jpeg_quality($quality=75)

[*] {

[*] //jpeg quality

[*] $this->img["quality"]=$quality;

[*] }

[*]

[*] function set_logo($logofile) {

[*] $this->logo['use_logo'] = true;

[*] $this->logo['src'] = imagecreatefrompng($logofile);

[*] imagesavealpha($this->logo['src'], true);

[*] imagealphablending($this->logo['src'], false)

[*] $this->logo['largura'] = imagesx($this->logo['src']);

[*] $this->logo['altura'] = imagesy($this->logo['src']);

[*]

[*] $this->logo['dest_x'] = $this->img['lebar_thumb'] - $this->logo['largura'];

[*] $this->logo['dest_y'] = $this->img['tinggi_thumb'] - $this->logo['altura'];

[*] }

[*] function show()

[*] {

[*] //show thumb

[*] @Header("Content-Type: image/".$this->img["format"]);

[*]

[*] /* change ImageCreateTrueColor to ImageCreate if your GD not supported ImageCreateTrueColor function*/

[*] $this->img["des"] = imagecreatetruecolor($this->img["lebar_thumb"],$this->img["tinggi_thumb"]);

[*] @imagecopyresampled ($this->img["des"], $this->img["src"], 0, 0, 0, 0, $this->img["lebar_thumb"], $this->img["tinggi_thumb"], $this->img["lebar"], $this->img["tinggi"]);

[*]

[*] if($this->logo['use_logo'] == true) {

[*] imagecopymerge($this->img['des'], $this->logo['src'], $this->logo['dest_x'], $this->logo['dest_y'], 0, 0, $this->logo['largura'], $this->logo['altura'], 100);

[*] }

[*] if ($this->img["format"]=="JPG" || $this->img["format"]=="JPEG") {

[*] //JPEG

[*] imageJPEG($this->img["des"],"",$this->img["quality"]);

[*] } elseif ($this->img["format"]=="PNG") {

[*] //PNG

[*] imagePNG($this->img["des"]);

[*] } elseif ($this->img["format"]=="GIF") {

[*] //GIF

[*] imageGIF($this->img["des"]);

[*] } elseif ($this->img["format"]=="WBMP") {

[*] //WBMP

[*] imageWBMP($this->img["des"]);

[*] }

[*] }

[*]

[*] function save($save="")

[*] {

[*] //save thumb

[*] if (empty($save)) $save=strtolower("./thumb.".$this->img["format"]);

[*] /* change ImageCreateTrueColor to ImageCreate if your GD not supported ImageCreateTrueColor function*/

[*] $this->img["des"] = imagecreatetruecolor($this->img["lebar_thumb"],$this->img["tinggi_thumb"]);

[*] @imagecopyresampled ($this->img["des"], $this->img["src"], 0, 0, 0, 0, $this->img["lebar_thumb"], $this->img["tinggi_thumb"], $this->img["lebar"], $this->img["tinggi"]);

[*]

[*] if ($this->img["format"]=="JPG" || $this->img["format"]=="JPEG") {

[*] //JPEG

[*] imageJPEG($this->img["des"],"$save",$this->img["quality"]);

[*] } elseif ($this->img["format"]=="PNG") {

[*] //PNG

[*] imagePNG($this->img["des"],"$save");

[*] } elseif ($this->img["format"]=="GIF") {

[*] //GIF

[*] imageGIF($this->img["des"],"$save");

[*] } elseif ($this->img["format"]=="WBMP") {

[*] //WBMP

[*] imageWBMP($this->img["des"],"$save");

[*] }

[*] }

[*]}

 

O problema está na função set_logo(), que não deixa a logo com transparência alpha.

 

Alguém sabe como consertar???

Compartilhar este post


Link para o post
Compartilhar em outros sites

×

Informação importante

Ao usar o fórum, você concorda com nossos Termos e condições.