Jump to content
Claris Engage 2025 - March 25-26 Austin Texas ×
The Claris Museum: The Vault of FileMaker Antiquities at Claris Engage 2025! ×

This topic is 6700 days old. Please don't post here. Open a new topic instead.

Recommended Posts

Posted

I'm revising existing PHP code and trying to change this:

:D


 to:



an output that adds a textual watermark.



I've got part of it (this function)
$img = imagecreatefromjpeg($img_src);

$white = imagecolorallocate($img, 255, 255, 255);

$imagestring($img, 3, 5, imagesy($img)-20, 'Watermark', $white); 

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

imagejpeg($img);




I'm just not sure how to "call" the function (passing the $img_src) to display the image rather than using the HTML img.



If I include 
header('Content-type: image/jpeg');

, as recommended, I get an error saying the header is already called (and it is). If I don't include it, I get the image (as bin-hex "text"), rather than the image!

Source for above code

Posted

NEVER MIND! I figured it out myself :D

1. Create a file called "v_watermark.php":

<?php  

// Load image

$image = imagecreatefromjpeg( '../'.$_GET['pic_path'] );

 if ($image == false) { echo 'no image'; die(); }



// Add colored text

$white = imagecolorallocate($image, 255, 255, 255);

imagestring($image, 3, 5, imagesy($image)-20, 'Watermark text', $white);



// Display image

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

// header('Content-Disposition: inline; filename=' . $_GET['src'] );

imagejpeg($image);

// die();



?>




2. Then pass the imagepath to the 'page' (even the name of the image dynamically, if desired):



Of course, you can have different image types and different color types and change everything about the text based on the size of the image. Try this link for more info: Dynamic Watermarking with PHP

This topic is 6700 days old. Please don't post here. Open a new topic instead.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.