mrjameer Posted March 25, 2007 Share Posted March 25, 2007 hi, i want to add the text to my images.here is my code but it is adding the text to only first image(horses.jpg) and displaying that image. this is my code.i want to add www.abc.com on both images. any of your idea will be appreciated.please find where iam wrong. <?php $arr1=array('horses.jpg','leop.jpg'); for($i=0; $i<count($arr1); $i++) { $image = imagecreatefromjpeg($arr1[$i]); $font_size = 12; $color = imagecolorallocate($image, 205,205,255); $black = imagecolorallocate($image, 0,0,0); ImageTTFText ($image, $font_size, 0, 01, 10, $black, "../fonts/ARIALBD.TTF","www.abcd.com"); ImageTTFText ($image, $font_size, 0, 00, 9, $color, "../fonts/ARIALBD.TTF","www.abcd.com"); header("Content-type: image/jpeg"); imagejpeg($image); imagedestroy($image); } ?> thanks mrjameer Quote Link to comment https://forums.phpfreaks.com/topic/44229-adding-text-on-images/ Share on other sites More sharing options...
Barand Posted March 25, 2007 Share Posted March 25, 2007 Have a separate script to manipulate dynamic images :: imagetext.php :: <?php $file = $_GET['file']; $image = imagecreatefromjpeg($file); $font_size = 12; $color = imagecolorallocate($image, 205,205,255); $black = imagecolorallocate($image, 0,0,0); ImageTTFText ($image, $font_size, 0, 01, 10, $black, "../fonts/ARIALBD.TTF","www.abcd.com"); ImageTTFText ($image, $font_size, 0, 00, 9, $color, "../fonts/ARIALBD.TTF","www.abcd.com"); header("Content-type: image/jpeg"); imagejpeg($image); imagedestroy($image); ?> Place images on another page with something like this <?php $arr1 = array ('horses.jpg', 'leop.jpg'); foreach ($arr1 as $file) { echo "<img src='imagetext.php?file=$file' /> <br />"; } ?> Quote Link to comment https://forums.phpfreaks.com/topic/44229-adding-text-on-images/#findComment-214836 Share on other sites More sharing options...
mrjameer Posted March 26, 2007 Author Share Posted March 26, 2007 hi, thanks for your reply.it works fantastic.here i have another problem.the code is adding the sitename to the image and displaying.ok. i want to add the site name to the image while uploading the image in to directory.here is my code <?php $uniq = substr( md5(uniqid (rand())), 0, 10 ); $ext = strtolower( substr($_FILES['uploadFile'. $a]['name'], -3)); $att_path="/uploads/"; for($a=0;$a<$uploadNeed;$a++) { if($ext==jpg) { $files=$_FILES['uploadFile'. $a]['name']; $arr1=array($files); foreach ($arr1 as $file) { $all="<img src='textonimage5.php?file=$file'>"; move_uploaded_file($all, $att_path."/".$uniq.".".$ext ); } } ?> this code is not adding the name to image while uploading into directory.please correct me where iam wrong. thanks mrjameer Quote Link to comment https://forums.phpfreaks.com/topic/44229-adding-text-on-images/#findComment-215313 Share on other sites More sharing options...
Barand Posted March 26, 2007 Share Posted March 26, 2007 You need a different technique from that for displaying dynamic images try (untested) <?php function addTextToFile($infile, $outfile) { $image = imagecreatefromjpeg($infile); $font_size = 12; $color = imagecolorallocate($image, 205,205,255); $black = imagecolorallocate($image, 0,0,0); ImageTTFText ($image, $font_size, 0, 01, 10, $black, "../fonts/ARIALBD.TTF","www.abcd.com"); ImageTTFText ($image, $font_size, 0, 00, 9, $color, "../fonts/ARIALBD.TTF","www.abcd.com"); imagejpeg($image, $outfile, 100); // save to outfile imagedestroy($image); } $att_path="/uploads/"; for($a=0;$a<$uploadNeed;$a++) { $uniq = substr( md5(uniqid (rand())), 0, 10 ); $ext = strtolower( substr($_FILES['uploadFile'. $a]['name'], -3)); if($ext=='jpg') { $file=$_FILES['uploadFile'. $a]['tmp_name']; // add text and write to new location addTextToFile($file, $att_path . $uniq.".".$ext); } } ?> Quote Link to comment https://forums.phpfreaks.com/topic/44229-adding-text-on-images/#findComment-215526 Share on other sites More sharing options...
mrjameer Posted March 26, 2007 Author Share Posted March 26, 2007 hi barand, thank you very much.the code works excellent.you caught me. thanks mrjameer Quote Link to comment https://forums.phpfreaks.com/topic/44229-adding-text-on-images/#findComment-215550 Share on other sites More sharing options...
mrjameer Posted March 27, 2007 Author Share Posted March 27, 2007 hi barand, what about the psd files.can i display the .psd files same as jpg and png's. for example if i use this code it is not displaying the .psd image <?php $files=array('free_site_s2.psd','abc.psd'); $arr1 = array($files); foreach ($arr1 as $file) { echo "<img src='classPhpPsdReader.php?file=$file'>"; } ?> and in the classPhpPsdReader.php i add this code <?php $file = $_GET['file']; header("Content-type: image/jpeg"); imagejpeg(imagecreatefrompsd($file)); ?> thanks mrjameer Quote Link to comment https://forums.phpfreaks.com/topic/44229-adding-text-on-images/#findComment-216060 Share on other sites More sharing options...
Barand Posted March 27, 2007 Share Posted March 27, 2007 I don't have any experience of that class. Quote Link to comment https://forums.phpfreaks.com/topic/44229-adding-text-on-images/#findComment-216226 Share on other sites More sharing options...
dj-kenpo Posted March 27, 2007 Share Posted March 27, 2007 psd files are photoshop files, it has nothing to do with php, the clients browser must support them. which I don't believe any browser does.. as it's not a standard image file, it's made up of vector/raster and multi layers. Quote Link to comment https://forums.phpfreaks.com/topic/44229-adding-text-on-images/#findComment-216244 Share on other sites More sharing options...
mrjameer Posted March 27, 2007 Author Share Posted March 27, 2007 hi, i have downloaded that class from phpclasses.org.this class is used to convert the .psd files in to jpeg's or gif's and display it.when i display a single .psd file using this class,it is displaying good but when i try to display an array of .psd files it is displaying the first one only. thanks mrjameer Quote Link to comment https://forums.phpfreaks.com/topic/44229-adding-text-on-images/#findComment-216247 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.