title: Overwriting an existing image with GD Library?
body: <p>I have a simple question:</p>
  
  <p>Is it possible to just overwrite an image file, after changing it? I'm adding a watermark to an existing image on my server and want to save it as the exact same file in the same folder, hence overwrite the old image.</p>
  
  <p>I'm trying to save the image like so:</p>
  
  <pre><code>imagejpeg($img, $filesavestring)
  </code></pre>
  
  <p>The problem is something seems to go wrong since I still get only the original image without the watermark. Any input on how to solve this would be much appreciated!</p>
  
  <p>Thanks</p>
  
  <p>UPDATE:<br>
  I played around a little and when I worked around with a temp file, then deleted the old file and saved it under the same name again it worked. However with Marcs input in mind, I decided to rename the original files into filename-original and keep them, while saving the edited images as filename. It seems then that imagejpeg will in fact not let you overwrite files I guess. Thank you all for helping me out!</p>