Jump to content

Help with Transparency and Opacity


hroberts89436

Recommended Posts

Here is my Coding:

<?php

 

header('Content-Type: image/jpeg');

 

$watermark = imagecreatefrompng('watermark.png'); 

$watermark_width = imagesx($watermark); 

$watermark_height = imagesy($watermark); 

$image = imagecreatetruecolor($watermark_width, $watermark_height); 

$image = imagecreatefromjpeg($_GET['src']); 

$size = getimagesize($_GET['src']); 

 

$width = $size[0];

$height = $size[1];

 

if($width < $watermark_width){

$width_ratio = $width / $watermark_width;

$height_ratio = $height / $watermark_height;

$new_watermark_width = $watermark_width * $width_ratio - 15 ;

$new_watermark_height = $watermark_height * $height_ratio;

 

$newImg = imagecreatetruecolor($new_watermark_width, $new_watermark_height);

imagealphablending($newImg, false);

 

$transparent = imagecolorallocatealpha($newImg, 255, 255, 255, 127);

imagefill($newImg,0,0,$transparent);

imagesavealpha($newImg,true);

 

imagecopyresampled($newImg, $watermark, 0, 0, 0, 0, $new_watermark_width, $new_watermark_height, $watermark_width, $watermark_height);

 

$watermark_width = $new_watermark_width;

$watermark_height = $new_watermark_height;

 

$watermark = $newImg;

}

 

$dest_x = ( $width / 2) - ($watermark_width / 2); 

$dest_y = ( $height / 2) - ($watermark_height / 2); 

imagecopymerge($image, $watermark, $dest_x, $dest_y, 0, 0, $watermark_width, $watermark_height, 100); 

header('Content-Type: image/jpeg');

imagejpeg($image); 

imagedestroy($image); 

imagedestroy($watermark); 

 

?>

 

What it does is take a PNG Image, and place it over a jpeg, when I display the image on my website.  Basically a way to help prevent someone from stealing my image.  What I would like to do is this:

 

The png image I am using has a single color rgb(225,225,225), with a transparent background.  I would like to take this color and make it semi opaque so that the jpeg does show thru, but the png image is still visible enough to keep people from wanting to print screen the image and steal it

 

The result can be seen at http://www.robertsfamilytree.org/genealogy/showmedia.php?&mediaID=147&medialinkID=163&albumlinkID=&page=4

 

I need any help on this i can get.

 

Thanks in advance

 

 

Link to comment
https://forums.phpfreaks.com/topic/147839-help-with-transparency-and-opacity/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.