note 70946 added to function.imagettftext
| From: | benatevolutioncomputingcouk at osu1 dot php dot net | Date: | Sun, 05 Nov 2006 21:25:32 +0000 |
| Subject: | note 70946 added to function.imagettftext | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-119412@lists.php.net to get a copy of this message | ||
A centralised text watermark - of any length, that automatically sizes to about 70% of the width,
and can be rotated to any angle.
<?php
/* Get image info */
$Image = @ImageCreateFromJPEG ("YourImage.jpg") ;
$sx = imagesx($Image) ;
$sy = imagesy($Image) ;
if ($WatermarkNeeded)
{
/* Set text info */
$Text="Copyright Ben Clay" ;
$Font="arial.ttf" ;
$FontColor = ImageColorAllocate ($Image,255,255,255) ;
$FontShadow = ImageColorAllocate ($Image,0,0,0) ;
$Rotation = 30 ;
/* Make a copy image */
$OriginalImage = ImageCreateTrueColor($sx,$sy) ;
ImageCopy ($OriginalImage,$Image,0,0,0,0,$sx,$sy) ;
/* Iterate to get the size up */
$FontSize=1 ;
do
{
$FontSize *= 1.1 ;
$Box = @ImageTTFBBox($FontSize,0,$Font,$Text);
$TextWidth = abs($Box[4] - $Box[0]) ;
$TextHeight = abs($Box[5] - $Box[1]) ;
}
while ($TextWidth < $sx*0.7) ;
/* Awkward maths to get the origin of the text in the right place */
$x = $sx/2 - cos(deg2rad($Rotation))*$TextWidth/2 ;
$y = $sy/2 + sin(deg2rad($Rotation))*$TextWidth/2 + cos(deg2rad($Rotation))*$TextHeight/2 ;
/* Make shadow text first followed by solid text */
ImageTTFText ($Image,$FontSize,$Rotation,$x+4,$y+4,$FontShadow,$Font,$Text);
ImageTTFText ($Image,$FontSize,$Rotation,$x,$y,$FontColor,$Font,$Text);
/* merge original image into version with text to show image through text */
ImageCopyMerge ($Image,$OriginalImage,0,0,0,0,$sx,$sy,50) ;
}
ImageJPEG ($Image) ;
?>
----
Server IP: 85.116.0.130
Probable Submitter: 82.69.127.39
----
Manual Page -- http://www.php.net/manual/en/function.imagettftext.php
Edit -- https://master.php.net/note/edit/70946
Del: integrated -- https://master.php.net/note/delete/70946/integrated
Del: useless -- https://master.php.net/note/delete/70946/useless
Del: bad code -- https://master.php.net/note/delete/70946/bad+code
Del: spam -- https://master.php.net/note/delete/70946/spam
Del: non-english -- https://master.php.net/note/delete/70946/non-english
Del: in docs -- https://master.php.net/note/delete/70946/in+docs
Del: other reasons-- https://master.php.net/note/delete/70946
Reject -- https://master.php.net/note/reject/70946
Search -- https://master.php.net/manage/user-notes.php