0

I have a simple facebook aplication. I have the index.php and the image.php which when accessed it creates an image with a random text on it(at least this is what i want to get from the script). Here is the image.php: http://pastebin.com/B4JhHcfj

The script is incomplete because i don't know how to get the text on the generated image. Example: I access the image.php, i get a image with a random text on it.If i access again the link the same image with the random text on it will be shown.Thanks

3
  • Do you want to get attached text on the image generated from your application or you want to insert a water mark on it ?
    – bizzr3
    Feb 7, 2012 at 20:24
  • Ok i have an answer for watermarking images did you want to give it to you ? (i searched over the net but cant find any solution for find something on an image directly with php)
    – bizzr3
    Feb 7, 2012 at 20:29
  • sure. any help will be more then great. Feb 7, 2012 at 20:32

3 Answers 3

1

Ok , you can use GD to watermark images , the complete script for watermarking :

<?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']);  
$dest_x = $size[0] - $watermark_width - 5;  
$dest_y = $size[1] - $watermark_height - 5;  
imagecopymerge($image, $watermark, $dest_x, $dest_y, 0, 0, $watermark_width, $watermark_height, 100); 
imagejpeg($image);  
imagedestroy($image);  
imagedestroy($watermark);  

?>

please note that , this script create watermarks on the fly , if you want to save watermarked image you must use imagejpeg() function with this way :

imagejpeg($image,'watermarked_img.jpg'); 

and you also use .htaccess to redirect all image request to your watermark.php,create .htaccess file and paste this code on it :

RewriteEngine on
RewriteRule ^([^thumb].*\.[jJ].*)$ watermark.php?src=$1

good luck.

0

I presume from your question, you have already included GD and that your PHP script generates the graphic using GD.

Firstly, you have to ensure that the required fonts are installed in the folder(s) where PHP will look for them.

Then, you should take a look at the following function, ImageTTFText:

http://php.net/manual/en/function.imagettftext.php

0

I did a PHP class to make it easier:

http://alvarotrigo.com/blog/using-php-gd-library-to-write-text-over-images-using-truetype-fonts/#comment-1048371709

It works with true type fonts (ttf) to be able to write text in big font sizes.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.