Php watermak, need help fixing working code!!!1

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
theCro
Forum Newbie
Posts: 10
Joined: Tue Jan 15, 2008 7:11 am

Php watermak, need help fixing working code!!!1

Post by theCro »

Ok here is my code for posting watermark over image:

Code: Select all

<?php  
$podaci = GetImageSize($_GET["mapa"] . $_GET["foto"]);
$foto_u_stazi = $_GET["mapa"] . $_GET["foto"];
 
$mapa3 = $_GET["mapa"];
$mapa4 = strstr($mapa3, "orginal");
 
$percent = 0.45;
 
/*if($mapa4 == "orginal/") { $water_u_stazi = "../img/057watermark.png"; } else
{ $water_u_stazi = "../img/057watermark2.png"; }
*/
$water_u_stazi = "watermark.png";
 
$height = $podaci[1];
$width = $podaci[0];
 
if($podaci["mime"] == "image/jpeg") {
//header("Content-type: image/jpeg");
$podloga = imagecreatefromjpeg ($foto_u_stazi);
}
 
$color = imagecolorallocate($podloga, 255, 255, 255);
$color2 = imagecolorallocate($podloga, 0, 0, 0);
 
$watermark = imagecreatefrompng($water_u_stazi); 
$watermark_width = imagesx($watermark); 
$watermark_height = imagesy($watermark); 
imagecolortransparent($watermark, $color2);
 
//$image = imagecreatetruecolor($watermark_width, $watermark_height); 
 

if($_GET["type"] == "1") {
 
 $dest_x = $width - $watermark_width - 10; 
 $dest_y = $height - $watermark_height - 10; 
 imagecopymerge($podloga, $watermark, $dest_x, $dest_y, 0, 0, $watermark_width, $watermark_height, 67);
 
} else {
 $newwidth = $watermark_width * $percent;
 $newheight = $watermark_height * $percent;
 
 $new_water = imagecreatetruecolor($newwidth, $newheight);
 
 imagecopyresampled($new_water, $watermark, 0, 0, 0, 0, $newwidth, $newheight, $watermark_width, $watermark_height);
 
 $color3 =  imagecolorat ($new_water , 0, 0);
    imagecolortransparent($new_water, $color3);
 
 $dest_x = $width - $newwidth - (10); 
 $dest_y = $height  - $newheight - (10); 
 
 imagecopymerge($podloga, $new_water, $dest_x, $dest_y, 0, 0, $newwidth, $newheight, 70);  
 
}
 
 
header("Content-type: image/png");
imagepng($podloga);
 
//===============================================================

?>
this works as http://www.site.com/foto.php?foto=image ... to/&type=2
however, because of this 'foto' twice at the top, i'm unable to, for example, put watermark on other image than in folder site.com/foto.

what i'd like to do is be able to give watermak image on whatever jpg file on my server i want.. so it should look like http://www.site.com/foto.php?foto=image ... er/&type=2

that's basically it.

can someone try to help me fixing my current working code? thanks!
theCro
Forum Newbie
Posts: 10
Joined: Tue Jan 15, 2008 7:11 am

Re: Php watermak, need help fixing working code!!!1

Post by theCro »

anyone?
User avatar
Jade
Forum Regular
Posts: 908
Joined: Sun Dec 29, 2002 5:40 pm
Location: VA

Re: Php watermak, need help fixing working code!!!1

Post by Jade »

You need to use an absolute path not a relative path to the image.
Post Reply