• Hi there,

    I know you can’t possibly add support for every third-party plugin out there, but I was hoping you might be able to suggest a way that we can use different Imsanity settings for forms where site visitors upload images via a Gravity Form?

    Perhaps an option for like:
    “Images uploaded by non-logged in users: max height/width”
    (that would be flexible to a lot more than gravity forms)

    Or might there be some small code snippet we could use to set these restrictions for Gravity Forms file uploads?

    Happy to answer any questions; thanks for considering!

Viewing 6 replies - 1 through 6 (of 6 total)
  • Plugin Author nosilver4u

    (@nosilver4u)

    Hi Jason,
    The upload conditions are infinitely extendable via this filter:
    apply_filters( 'imsanity_get_max_width_height', array( $w, $h ), $source );

    From there, you can pick whatever conditions you like, and return the dimensions as an array, like so:
    return array( 1920, 1080 );

    If you want to use $source variable in your conditions, it is a numerical value:
    1 = uploaded to a post
    2 = uploaded to the library
    4 = anywhere else

    Thread Starter Jason LeMahieu (MadtownLems)

    (@madtownlems)

    Thanks for the quick reply.

    Unfortunately, what I learned by trying to do this is that Gravity Forms file uploads don’t actually get processed by Imsanity at ALL, so this filter doesn’t do anything. :/

    Cheers

    Thread Starter Jason LeMahieu (MadtownLems)

    (@madtownlems)

    Is there a function available via Imsanity that I can pass a file path to, along with dimensions, to do the resizing?

    like, imsanity_resize_file( $path_to_file, $max_dimensions_array )?

    thanks!

    EDIT: I found imsanity_image_resize. I’ll try making gravity forms call that after uploading. thanks!

    Plugin Author nosilver4u

    (@nosilver4u)

    Yup, you can use that one or imsanity_handle_upload( $params ) where $params is an array like so:

    array(
        'file' = '/the/full/path/to/an/image.jpg',
        'type' = 'image/jpeg',
    );

    But imsanity_image_resize() is probably easier for your use, and it’s what imsanity_handle_upload() ends up calling anyway ??

    Thread Starter Jason LeMahieu (MadtownLems)

    (@madtownlems)

    I’m getting around to trying this out, and unfortunately I don’t think it does exactly what I want.

    I was hoping I could simply resize the file in place; just overwrite the file in the existing filepath with a smaller version. But it looks like imsanity_image_resize explicitly forbids this.

    // Make sure that the destination file does not exist.
    if ( file_exists( $dest_file ) ) {
    $dest_file = $editor->generate_filename( ‘TMP’, $dest_path );
    }

    Any ideas? and is it possible I’m just greatly overthinking / overcomplicating this?

    Cheers mate

    Plugin Author nosilver4u

    (@nosilver4u)

    Yeah, if you use imsanity_image_resize() directly, then you need to check the filesize afterwards and then overwrite the original.
    Basically doing this portion of imsanity_handle_upload():

    $resizeresult = imsanity_image_resize( $oldpath, $neww, $newh, false, null, null, 82 );
    if ( $resizeresult && ! is_wp_error( $resizeresult ) ) {
    	$newpath = $resizeresult;
    	if ( is_file( $newpath ) && filesize( $newpath ) < filesize( $oldpath ) ) {
    		// we saved some file space. remove original and replace with resized image.
    		unlink( $oldpath );
    		rename( $newpath, $oldpath );
    	} elseif ( is_file( $newpath ) ) {
    		// the resized image is actually bigger in filesize (most likely due to jpg quality).
    		// keep the old one and just get rid of the resized image.
    		unlink( $newpath );
    	}
    }
Viewing 6 replies - 1 through 6 (of 6 total)
  • The topic ‘Different sizes for front-end submissions (such as via Gravity Forms)?’ is closed to new replies.