title: image manipulation width and height setting
body: <p>in my project i just do image watermarking or image combine it's working fine and code for that.</p>
  
  <pre><code>&lt;!DOCTYPE html&gt;
  &lt;html&gt;
  &lt;head&gt;
  &lt;title&gt;test&lt;/title&gt;
  &lt;/head&gt;
  &lt;body&gt;
  &lt;?php
  if(isset($_POST['submit']))
  {
  // Give the Complete Path of the folder where you want to save the image    
  $folder="uploads/";
  move_uploaded_file($_FILES["fileToUpload"]["tmp_name"], "$folder".$_FILES["fileToUpload"]["name"]);
  $file='uploads/'.$_FILES["fileToUpload"]["name"];
  
  $uploadimage=$folder.$_FILES["fileToUpload"]["name"];
  $newname= time();
  
  $ext = pathinfo($_FILES["fileToUpload"]["name"], PATHINFO_EXTENSION);
  
  // Set the thumbnail name
  $thumbnail = $folder.$newname.".".$ext; 
  $imgname=$newname.".".$ext;
  
  // Load the mian image
  if ($ext=="png" || $ext=="PNG") {
  $source = imagecreatefrompng($uploadimage);
  }
  else if ($ext=="gif" || $ext=="GIF") {
  $source = imagecreatefromgif($uploadimage);
  }
  else if ($ext=="bmp" || $ext=="BMP") {
  $source = imagecreatefrombmp($uploadimage);
  }
  else{
  $source = imagecreatefromjpeg($uploadimage);
  }
  
  // load the image you want to you want to be watermarked
  $watermark = imagecreatefrompng('uploads/logo1.png');
  
  // get the width and height of the watermark image
  $water_width = imagesx($source)/2;
  $water_height = imagesy($watermark);
  
  // get the width and height of the main image image
  $main_width = imagesx($source);
  $main_height = imagesy($source);
  
  $im_middle_w = $main_width/2;
  $im_middle_h = $main_height/2;
  
  // Set the dimension of the area you want to place your watermark we use 0
  // from x-axis and 0 from y-axis 
  $dime_x = $im_middle_w - $water_width/2;
  $dime_y = $im_middle_h - $water_height/2;
  
  // copy both the images
  imagecopy($source, $watermark, $dime_x, $dime_y, 0, 0, $water_width, $water_height);
  
  // Final processing Creating The Image
  imagejpeg($source, $thumbnail, 100);
  unlink($file);
  }
  ?&gt;
  &lt;img src='uploads/&lt;?php echo $imgname;?&gt;'&gt;
  &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>
  
  <p>but problem with setting <strong>$water_width</strong> and i want set as half of my source image. but when i have source image of less width or more width compare to $water_width it's set it like that. see image when source image width is more.</p>
  
  <p><a href="https://i.stack.imgur.com/NlY5p.jpg" rel="noreferrer"><img src="https://i.stack.imgur.com/NlY5p.jpg" alt="enter image description here"></a>
  and when width is less.
  <a href="https://i.stack.imgur.com/JHj5v.jpg" rel="noreferrer"><img src="https://i.stack.imgur.com/JHj5v.jpg" alt="enter image description here"></a>
  so my problem is how to set <strong>$water_width</strong> as half of source image width?</p>
  
  <p>by Alex your answer it's came up like this.
  <a href="https://i.stack.imgur.com/7Vlrp.jpg" rel="noreferrer"><img src="https://i.stack.imgur.com/7Vlrp.jpg" alt="enter image description here"></a></p>