Last active
July 20, 2019 13:43
-
-
Save endurtech/536157d7f4c2aed85c1b97a944ab55c4 to your computer and use it in GitHub Desktop.
UNTESTED - Gravity Forms Image Upload Resizer
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?php | |
| // Gravity Forms Image Upload Resizer. Replace _1 with your Form ID | |
| add_action( "gform_after_submission_1", "gf_resize_images", 10, 2 ); | |
| function gf_resize_images( $entry, $form ) | |
| { | |
| // Replace 2 with field ID of upload field | |
| $url = $entry[2]; | |
| $parsed_url = parse_url( $url ); | |
| $path = $_SERVER['DOCUMENT_ROOT'] . $parsed_url['path']; | |
| $image = wp_get_image_editor( $path ); | |
| if ( ! is_wp_error( $image ) ) | |
| { | |
| // Replace 800,600 with desired dimensions. If smaller, no crop applied. | |
| $result = $image->resize( 800, 600, false ); | |
| $result = $image->save($path); | |
| } | |
| } | |
| ?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment