Jump to content

Recommended Posts

Hi,

I have some code to put a text watermark on an image (using imagettftext). The code i have works in a php file on its own but when i add it to my existing page i get problems.

Firstly i had a problem with the "headers already sent..." problem but that was because i had header('Content-type: image/jpg'); with the rest of my code.

 

Now i have moved "header('Content-type: image/jpg');" to the beginning of my html file and the rest of the PHP code where i want the image on my page. Now i dont get any image displayed.

 

The code im using is:

<?php
//load image
$im = imagecreatefromjpeg('C11ABX.jpg');

//figure out where to put the text
$imagesize = getimagesize('C11ABX.jpg');
$x_offset = 50;
$y_offset = $imagesize[1] - 20;

//text color
$textcolor = imagecolorallocate($im, 0xFF, 0xFF, 0xFF);

//set font
$font = 'detaranto.ttf';

//set size
$size = '20';

//set angle
$angle = '45';

//set text
$text = 'SAMPLE';

imagettftext ($im ,$size ,$angle ,$x_offset ,$y_offset ,$textcolor ,$font ,$text );

//output watermarked image
imagejpeg($im);
?>

 

Any help would be great.

 

Thanks

Link to comment
https://forums.phpfreaks.com/topic/242256-image-watermark-text-problem/
Share on other sites

The code i have works in a php file on its own but when i add it to my existing page i get problems.

That's how it works. You have it in a separate file, and then you use that php file as you would any other image resource:

 

<img src="thatphpfile.php" alt="..." />

Oh ok, thanks very much. That works.

Eventually I would like to watermark each image in a certain folder (the photos im putting on the site) so i dont really want lots of PHP files if neccessary.

 

Also to do that i'd like to know how to use this code (or something similar) to use this code to put a watermark on each image instead of just stating each filename.

 

Im guessing i would need something like <img src="image.php?imagename"> or something like that once i have the code to get all images.

 

Thanks

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.