2

This question already has an answer here:

My aim is to upload an image and completely replace the original source image with a custom image size, as if the custom image sized file was the uploaded image.

For example, I have custom image size wpse, and I want to replace the original image completely with this file upon upload.

How is this possible?

Potential approach could be to hook into the upload process, edit the guid key in the wp_posts table with the URL of the wpse image, then delete the source uploaded file. I'm sure there are other values which needs to be updated.

marked as duplicate by fuxia Mar 1 '16 at 16:37

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

  • It is unclear to me what you are asking... Are you saying you have an image that is already uploaded that you don't want to delete from the database in order to preserve it's id but instead you want to phsyically replace the image that the database entry refers to with a new image that has your custom image size wpse applied? If so, why can't you just delete the existing, upload the new (with custom image size) then re-attach the new image to the post that the old image was attached to? Interested to know more... – userabuser Mar 1 '16 at 15:02
  • 2
    So replacing the full size image with a specific image size, right? Like this question »Automatically replace original uploaded image with large image size« I suppose. – Nicolai Mar 1 '16 at 15:07
  • @ialocin while keeping the same ID from how the last paragraph makes it sound. I imagine she also wants the other image sizes gone too. There's something like this that works with featured images but the whole scenario seems unpractical. – Howdy_McGee Mar 1 '16 at 15:09
  • 1
    @ChristineCooper If I'm not completely misunderstanding you, then the question I linked does that. – Nicolai Mar 1 '16 at 15:14
  • 2
    @ialocin I can confirm that this is the correct answer. Had to adjust the code somewhat but it works! Didn't think I would get a good solution to this, thanks for linking it!! – Christine Cooper Mar 1 '16 at 15:41