Iam just stuck on this code I want to add an water mark on in between this process but I don't know how to give it. If the user select upload on the first image the image will uploaded and it will show in the right side. I want to give water mark on each image while user uploading. Please help me if any one can correct this code it will be help full please add the right code in your reply below I have added all the code in that page.

<?php
session_start();
include_once('admin/connection.php');
include_once('functions.php');
include_once('m_loginfunctions.php');

if(checkLoggedin()) 
{ 
$uemail = mysql_real_escape_string($_SESSION['user_sincere']);
$upass = decode3t(mysql_real_escape_string($_SESSION['pass_sincere']));
}
else
{
header("Location: login.php");
}

$str="";$str2="";
$img_str="";$img_str2="";
$regno="";$pid="";
$phto0='';$phto1 ='';$phto2 ='';$phto3 ='';$phto4 ='';$phto5 ='';$phto6='';$phto7='';
$thumb_img="";$thumb_report="";$image_to_be_cropped="";$thumb_full="";


$selquery=mysql_query("select * from `pdetails` where `email`='$uemail' ") or die(mysql_error());

if(mysql_num_rows($selquery)==1)
{
$fet=mysql_fetch_array($selquery);

$regno=$fet['regno'];
$pid = $fet['pid'];
$phto0 = $fet['phto0'];
$phto1 = $fet['phto1'];
$phto2 = $fet['phto2'];
$phto3 = $fet['phto3'];
$phto4 = $fet['phto4'];
$phto5 = $fet['phto5'];
$phto6 = $fet['phto6'];
$phto7 = $fet['phto7'];//kalyana kuri mage


}

if( isset($_GET['phto']) && $_GET['phto']!='' )
{
      $phto = $_GET['phto'];

      switch($phto)
      {

        case 0: $query ="update `pdetails` set `phto0`='' where `pid`='{$pid}' ";
                mysql_query($query);
                  if(mysql_affected_rows()==1){
                  unlink("admin/images/".$phto0); 
                  header("Location: photo.php");
                  }//deleted

                  break;

        case 1: $query ="update `pdetails` set `phto1`='' where `pid`='{$pid}' ";
                mysql_query($query);
                  if(mysql_affected_rows()==1){
                  unlink("admin/images/".$phto1); 
                  header("Location: photo.php");
                  }//deleted

                  break;
        case 2: $query ="update pdetails set phto2='' where pid='{$pid}' ";
                mysql_query($query);
                  if(mysql_affected_rows()==1){
                  unlink("admin/images/".$phto2);
                  header("Location: photo.php");
                  }//deleted

                  break;
        case 3: $query ="update pdetails set phto3='' where pid='{$pid}' ";
                mysql_query($query);
                  if(mysql_affected_rows()==1){
                  unlink("admin/images/".$phto3);
                   header("Location: photo.php");
                  }//deleted

                  break;
        case 4: $query ="update pdetails set phto4='' where pid='{$pid}' ";
                mysql_query($query);
                  if(mysql_affected_rows()==1){
                  unlink("admin/images/".$phto4);
                   header("Location: photo.php");
                  }//deleted

                  break;
        case 5: $query ="update pdetails set phto5='' where pid='{$pid}' ";
                mysql_query($query);
                  if(mysql_affected_rows()==1){
                  unlink("admin/images/".$phto5);
                   header("Location: photo.php");
                  }//deleted

                  break;
        case 6: $query ="update pdetails set phto6='' where pid='{$pid}' ";
                mysql_query($query);
                  if(mysql_affected_rows()==1){
                  unlink("admin/images/".$phto6);
                   header("Location: photo.php");
                  }//deleted

                  break;


        //kalyana kuri image
        case 7: $query ="update pdetails set phto7='' where pid='{$pid}' ";
                mysql_query($query);
                  if(mysql_affected_rows()==1){
                  unlink("admin/images/".$phto7);
                   header("Location: photo.php");
                  }//deleted

                  break;

        default: //do nothing         
      }//end switch
}



//image upload portion
for($i=0;$i<=7;$i++)
{

    if(isset($_POST["add_phto$i"]) )
    {

          if( $_FILES["phto$i"]["name"]=='' )
          {
              $img_str = 'Please select image for upload.' ;
          }

          else if(
                  (
                   ($_FILES["phto$i"]["type"] == "image/gif") ||
                   ($_FILES["phto$i"]["type"] == "image/jpeg")|| 
                   ($_FILES["phto$i"]["type"] == "image/pjpeg")
                   )
                    && 
                   ($_FILES["phto$i"]["size"] < 1048576)//means 1 mb 1024 bytes =1 Kb, 1024 Kb =1 mb 
                  )
          {

                 if($_FILES["phto$i"]["error"]>0)
                 {
                    $img_str= "upload error(image $i)";
                 }
                 else
                 { 
                        if($_FILES["phto$i"]["size"]!=0)
                        {
                          move_uploaded_file($_FILES["phto$i"]["tmp_name"],"admin/images/".$regno."_".$i.".jpg");
                          $phto =$regno."_".$i.".jpg";

                          $query = "update `pdetails` set `phto$i`='$phto' where `pid`='$pid' ";
                          $resultset= mysql_query($query);

                                if(mysql_affected_rows()==1)
                                {
                                    //$img_str2="Image uploaded successfully";
                                    header("Location:photo.php");
                                    exit;
                                }
                          }
                  }
            }

            else
            {
                $img_str= "(Image: $i) - Incompatible format or size exceeded 1 Mb.";
            }

    }//end if

}//end for



?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<link rel="stylesheet" type="text/css" href="css/basic.css" />
<script type="text/javascript" src="js/jquery-1.9.1.min.js"></script>
<script>
$(function(){
    $('#country').change(function(){
        $('#state').load('ajxcheck.php?cid='+$(this).val());
    });

});
</script>
<title>Sincere Matrimony</title>
</head>

<body>


<?php include('header.php') ; ?>




<table width="950" border="0" cellspacing="0" cellpadding="0" class="inner_page" align="center">
  <tr valign="top">
    <td width="650"  class="inner_contant">

    <div class="user">
    <?php include_once('user_menu.php') ; ?>
    <div class="user_cont">



<table class="login" cellpadding="3" cellpadding="2" border="0">
<tr height="30"><td colspan="2"></td></tr>
<tr><td class="heading4" colspan="2">Add Photo</td></tr>
<tr><td colspan="2">
<?php 
    if($img_str!="")
    {
    echo '<div class="rep">'.$img_str.'</div>';
    }
    if($img_str2!="")
    {
    echo '<div class="success_rep">'.$img_str2.'</div>';
    }
?>
</td></tr>

<tr>
  <td class="td_p1" valign="top" >Thumb Image (150x150) </td>

  <td class="td_p2">
    <form name="form0" action="" method="post" enctype="multipart/form-data">
    <input type="file" name="phto0" class="edit_phto_file"/>
    <input type="submit" value="Upload" name="add_phto0" class="edit_phto_submit"/>
    </form>

    <?php if($phto0!=''){?>
    <img src="admin/images/<?=$phto0?>" class="p_img"/>
    <a href='photo.php?phto=0' onClick="return confirm('Delete image ?')">
    <img src="admin/web_images/delete.gif" class="d_img" /> </a>
    <?php } ?>
  </td>
</tr>

<tr>
  <td class="td_p1" valign="top">Photo 1</td>

  <td class="td_p2">
    <form name="form1" action="" method="post" enctype="multipart/form-data">
    <input type="file" name="phto1" class="edit_phto_file"/>
    <input type="submit" value="Upload" name="add_phto1" class="edit_phto_submit"/>
    </form>

    <?php if($phto1!=''){?><img src="admin/images/<?=$phto1?>" class="p_img"/>
    <a href='photo.php?phto=1' onClick="return confirm('Delete image ?')">
    <img src="admin/web_images/delete.gif" class="d_img" /> </a>
    <?php } ?>
  </td>
</tr>
<tr>
  <td class="td_p1">Photo 2</td>

  <td class="td_p2" valign="top">
    <form name="form2" action="" method="post" enctype="multipart/form-data">
    <input type="file" name="phto2" class="edit_phto_file"/>
    <input type="submit" value="Upload" name="add_phto2" class="edit_phto_submit"/>
    </form>

    <?php if($phto2!=''){?><img src="admin/images/<?=$phto2?>" class="p_img" />
    <a href='photo.php?phto=2' onClick="return confirm('Delete image ?')">
    <img src="admin/web_images/delete.gif" class="d_img" /> </a>
    <?php } ?>
  </td>
</tr>
<tr>
  <td class="td_p1">Photo 3</td>

  <td class="td_p2" valign="top">
    <form name="form3" action="" method="post" enctype="multipart/form-data">
    <input type="file" name="phto3" class="edit_phto_file"/>
    <input type="submit" value="Upload" name="add_phto3" class="edit_phto_submit"/>
    </form>

    <?php if($phto3!=''){?><img src="admin/images/<?=$phto3?>" class="p_img" />
    <a href='photo.php?phto=3' onClick="return confirm('Delete image ?')">
    <img src="admin/web_images/delete.gif" class="d_img" /> </a>
    <?php } ?>
  </td>
</tr>
<tr>
  <td class="td_p1" valign="top">Photo 4</td>

  <td class="td_p2">
   <form name="form4" action="" method="post" enctype="multipart/form-data">
    <input type="file" name="phto4" class="edit_phto_file"/>
    <input type="submit" value="Upload" name="add_phto4" class="edit_phto_submit"/>
    </form>

    <?php if($phto4!=''){?><img src="admin/images/<?=$phto4?>" class="p_img" />
    <a href='photo.php?phto=4' onClick="return confirm('Delete image ?')">
    <img src="admin/web_images/delete.gif" class="d_img" /> </a>
    <?php } ?>
  </td>
</tr>
<tr>
  <td class="td_p1" valign="top">Photo 5</td>

  <td class="td_p2">
    <form name="form5" action="" method="post" enctype="multipart/form-data">
    <input type="file" name="phto5" class="edit_phto_file"/>
    <input type="submit" value="Upload" name="add_phto5" class="edit_phto_submit"/>
    </form>

    <?php if($phto5!=''){?><img src="admin/images/<?=$phto5?>" class="p_img" />
    <a href='photo.php?phto=5' onClick="return confirm('Delete image ?')">
    <img src="admin/web_images/delete.gif" class="d_img" /> </a>
    <?php } ?>
  </td>
</tr>
<tr>
  <td class="td_p1"  valign="top">Photo 6</td>

  <td class="td_p2">
    <form name="form6" action="" method="post" enctype="multipart/form-data">
    <input type="file" name="phto6" class="edit_phto_file"/>
    <input type="submit" value="Upload" name="add_phto6" class="edit_phto_submit"/>
    </form>

    <?php if($phto6!=''){?><img src="admin/images/<?=$phto6?>" class="p_img" />
    <a href='photo.php?phto=6' onClick="return confirm('Delete image ?')">
    <img src="admin/web_images/delete.gif" class="d_img" /> </a>
    <?php } ?>
  </td>
</tr>

<tr height="1">
<td colspan="2"><hr /></td>
</tr>

<tr>
  <td class="td_p1" valign="top">Thalakuri </td>

  <td class="td_p2">
    <form name="form7" action="" method="post" enctype="multipart/form-data">
    <input type="file" name="phto7" class="edit_phto_file"/>
    <input type="submit" value="Upload" name="add_phto7" class="edit_phto_submit"/>
    </form>

    <?php if($phto7!=''){?><img src="admin/images/<?=$phto7?>" class="p_img" />
    <a href='photo.php?phto=7' onClick="return confirm('Delete image ?')">
    <img src="admin/web_images/delete.gif" class="d_img" /> </a>
    <?php } ?>
  </td>
</tr>

  <tr height="30"><td colspan="2"></td></tr>
  <tr>
    <td class="td_p1"></td>
    <td class="td_p2">
    <a href="user.php" class="reg_link">Finish</a>
    </td>
  </tr>
</table>




    </div>
    </div>

   <p>&nbsp;</p> 

   </td>
   <td width="300" >
     <?php include('searchform_side.php') ;?>
   </td>
  </tr>
</table>



<?php include('footer.php') ; ?>


</body>
</html>
Member Avatar for diafol

WTH??

Are you talking about the php code? I'm assuming it's PHP as it's giving me a nosebleed.
Impossible to read as it's not properly indented.
And giving it a quick look, I can see many deprecated mysql_* functions.

If you want help on the PHP, please indent your code and re-post.

Hello If any one can't read the above code please go to http://pastebin.com/wqPNzG43 I don't know when Iam trying to edite the code it was showin correctly and after posting it was mixed. So please go to the above link and you can see all code please

honestly I didn't read your code because I don't know what you want to achieve here , normally I use function to create watermark on images, hope it help.

function create_watermark($img_name,$newname,$type)
{
    // check image type. The image type is sent as parameter 3 ($type). Note that for every image type a different function is used to create an image in memory from the uploaded file.
    $newname = "uploads/".$newname;
    if(!strcmp("image/jpg",$type) || !strcmp("image/jpeg",$type) || !strcmp("image/pjpeg",$type))
        $src_img=imagecreatefromjpeg($img_name);

    if(!strcmp("image/png",$type))
        $src_img=imagecreatefrompng($img_name);

    if(!strcmp("image/gif",$type))
        $src_img=imagecreatefromgif($img_name);

    // get image size, we'll need it later
    $old_x=imageSX($src_img);
    $old_y=imageSY($src_img);

    // create destination image Thumbnail
    $new_x = $old_x;
    $new_y = $old_y;
    $dst_img=ImageCreateTrueColor($new_x,$new_y);

    imagecopyresampled($dst_img,$src_img,0,0,0,0,$new_x,$new_y,$old_x,$old_y);

    // the watermark image will be named watermark.gif and will be located in images folder. If you intend to use other file, you will have to change this
    $watermark_file='images/watermark.gif';

    // you can setup the transparency used for watermark image.
    $transparency=40;


    $wext = pathinfo('images/watermark.gif', PATHINFO_EXTENSION);
    // create an image from watermark file
    if(!strcmp("jpg",$wext) || !strcmp("jpeg",$wext)) $watermark=imagecreatefromjpeg($watermark_file);

    if(!strcmp("png",$wext)) $watermark=imagecreatefrompng($watermark_file);

    if(!strcmp("gif",$wext)) $watermark=imagecreatefromgif($watermark_file);

    // get watermark width
    $watermark_width = imagesx($watermark);
    $watermark_height = imagesy($watermark);

    // place watermark image on the right left of the main image
    //$dest_x = $old_x - $watermark_width - 5;
    //$dest_y = $old_y - $watermark_height - 5;

    // uncomment these lines and comment the ones above if you want to place the watermark in the very center of the image
    $dest_x = (($new_x - $watermark_width)/2);
    $dest_y = (($new_y - $watermark_height)/2);

    // merge the two images
    imagecopymerge($dst_img, $watermark, $dest_x, $dest_y, 0, 0, $watermark_width, $watermark_height, $transparency);

    // copy the new created image to the destination file, in the images folder
    if(!strcmp("image/png",$type))  imagepng($dst_img,$newname);
    else if(!strcmp("image/gif",$type))  imagegif($dst_img,$newname);
    else imagejpeg($dst_img,$newname);

    // delete the images from memory
    imagedestroy($dst_img);
    imagedestroy($src_img);

}

if u put text content on image... use this function...

//code water mark
                function watermarkImage ($SourceFile, $WaterMarkText, $DestinationFile) 
{ 
    @unlink($DestinationFile);  
    $top = getimagesize($SourceFile);
    $info = getimagesize($SourceFile);
    $top = $top[1]/2;
    list($width, $height) = getimagesize($SourceFile);

    $image_p = imagecreatetruecolor($width, $height);   
    if ($info['mime'] == 'image/jpeg')
    {
        $image = imagecreatefromjpeg($SourceFile);
    }
    elseif ($info['mime'] == 'image/png')
    {
        $image = imagecreatefrompng($SourceFile);
    }

    imagecopyresampled($image_p, $image, 0, 0, 0, 0, $width, $height, $width, $height); 

    $font = 'arial.ttf';

    $font_size = ($width/10) * 0.5;//50;//($width * (100 / $width));

    $white = imagecolorallocate($image_p, 255, 255, 255);   
    imagettftext($image_p, $font_size+1, 30, ($width/2) - (($width/2) * 0.2) , ($height/2) + (($height/2) * 0.18), $white, $font, $WaterMarkText);

    //$black = imagecolorallocate($image_p, 0, 0, 0);
    //imagettftext($image_p, $font_size-1, 29.8, ($width/2) - (($width/2) * 0.2) , ($height/2) + (($height/2) * 0.18), $black, $font, $WaterMarkText);


   if ($DestinationFile<>'') {
    if ($info['mime'] == 'image/jpeg')
    {
      imagejpeg ($image_p, $DestinationFile, 100); 
    }
    elseif ($info['mime'] == 'image/png')
    {
        imagepng ($image_p, $DestinationFile, 9); 
    }
   } else {
    if ($info['mime'] == 'image/jpeg')
    {
      header('Content-Type: image/jpeg');

      imagejpeg($image_p, null, 100);
    }
    elseif ($info['mime'] == 'image/png')
    {
        header('Content-Type: image/png');

      imagepng($image_p, null, 100);
    }
   };

   imagedestroy($image); 

   imagedestroy($image_p); 

};

$SourceFile = $_FILES['file']['tmp_name'];//Source image
$DestinationFile = '../uploads/'.$extension.'';//Destination path 
$WaterMarkText = 'your text';//Watermark text

//Call the function to watermark the image
watermarkImage ($SourceFile, $WaterMarkText, $DestinationFile);

                //over
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.