Jump to content

adding text on images


mrjameer

Recommended Posts

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

Link to comment
https://forums.phpfreaks.com/topic/44229-adding-text-on-images/
Share on other sites

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 />";
}
?>

Link to comment
https://forums.phpfreaks.com/topic/44229-adding-text-on-images/#findComment-214836
Share on other sites

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

Link to comment
https://forums.phpfreaks.com/topic/44229-adding-text-on-images/#findComment-215313
Share on other sites

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);

    }
}
?>

Link to comment
https://forums.phpfreaks.com/topic/44229-adding-text-on-images/#findComment-215526
Share on other sites

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

Link to comment
https://forums.phpfreaks.com/topic/44229-adding-text-on-images/#findComment-216060
Share on other sites

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

Link to comment
https://forums.phpfreaks.com/topic/44229-adding-text-on-images/#findComment-216247
Share on other sites

Archived

This topic is now archived and is closed to further replies.

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