How to Resize Images Uploaded to Gravity Forms
Gravity Forms is a powerhouse plugin for building advanced forms in WordPress. One of its standout features is file uploads—including images.
But what happens when users upload massive, high-resolution images that bog down your server or slow down your site?
Good news: you can automatically resize uploaded images using a simple PHP snippet. In this post, we’ll walk you through how to implement it and tailor it to your specific form setup.
Why Resize Uploaded Images?
Automatically resizing images uploaded via Gravity Forms is a smart way to keep your site lean, fast, and user-friendly. With just a few lines of code, you can take control of your media uploads and ensure consistency across your site.
Here are a few compelling reasons to resize images on upload:
- Performance: Smaller images load faster and reduce server load.
- Storage: Large images eat up disk space quickly.
- Consistency: Resize images to a standard dimension for uniform display.
- Security: Prevent oversized or malicious uploads from affecting your site.
Resize Uploaded Images Code Snippet
Here is a handy PHP code snippet that will resize images uploaded via Gravity Forms:
How It Works
- Hook: gform_after_submission_1 triggers after form ID 1 is submitted.
- Field ID: $entry[2] refers to the image upload field (replace 2 with your actual field ID).
- Image Editor: wp_get_image_editor() loads the image for editing.
- Resize: The image is resized to 800×600 pixels (you can change this).
- Save: The resized image overwrites the original.
How to Customize
- Form ID: Change gform_after_submission_1 to match your form’s ID.
- Field ID: Update $entry[2] to match your image upload field.
- Dimensions: Modify 800×600 to your preferred width and height.
- Note, if the image is smaller than the supplied dimensions then no adjustments are made.
- Cropping: The third parameter in resize() is false, meaning no cropping. Set it to true if you want to crop.
Important Notes
- This snippet should be placed in your child theme’s functions.php file or a custom plugin.
- Always test on a staging site before deploying to production.
- This only works for image uploads—other file types will be ignored.
Bonus Tip: Validate Image Type
To make your snippet more robust, you can add a check to ensure the file is an image before resizing:
if ( strpos( mime_content_type( $path ), ‘image/’ ) === 0 ) { /* Proceed with resizing */ }
Conclusion
I welcome your thoughts, questions or suggestions on my article on how to resize images uploaded via a form with Gravity Forms.
You may support my work by sending me a tip using your Brave browser or by sending me a one time donation using your credit card.
Let me know if you found any errors within my article or if I may further assist you by answering any additional questions you may have.




