Created
August 16, 2016 01:43
-
-
Save fridaynext/6417368b89f93a7fe25eafa905ebe4c4 to your computer and use it in GitHub Desktop.
This file contains 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 | |
//resize images uploaded to Gravity Form 1. | |
add_action("gform_after_submission_1", "gf_resize_images", 10, 2); | |
function gf_resize_images($entry, $form) | |
{ | |
if( $url = pathinfo( $entry[18] ) ) { | |
$image = wp_get_image_editor($url); | |
if ( ! is_wp_error( $image ) ) | |
{ | |
//replace 640,480 with desired dimensions. false indicates not to crop image. | |
$image->resize( 1000,750,false ); | |
$image->set_quality(); | |
$image->save($url); | |
} | |
} | |
if( $url = pathinfo( $entry[21] ) ) { | |
$image = wp_get_image_editor($url); | |
if ( ! is_wp_error( $image ) ) | |
{ | |
//replace 640,480 with desired dimensions. false indicates not to crop image. | |
$image->resize( 1000,750,false ); | |
$image->set_quality(); | |
$image->save($url); | |
} | |
} | |
if( $url = pathinfo( $entry[22] ) ) { | |
$image = wp_get_image_editor($url); | |
if ( ! is_wp_error( $image ) ) | |
{ | |
//replace 640,480 with desired dimensions. false indicates not to crop image. | |
$image->resize( 1000,750,false ); | |
$image->set_quality(); | |
$image->save($url); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Thanks for this, but it didn't work for me - the values in my $entry object were URLs, so
pathinfo()
didn't work. Here's my refactored version, that does a generic job based off form and field names (no need o remember ids):