WordPress.org

Ready to get started?Download WordPress

Forums

How do I use the WP image functions in a page template? (3 posts)

  1. RonStrilaeff
    Member
    Posted 1 year ago #

    Sorry for the long title, but my goal is very specific.

    I know wp includes support for plupload, jcrop and the php gd library, but I'm running into dead-ends trying to implement some of that functionality on a custom page that will allow visitors to my website to do the following:

    1. drag and drop an image to a target drop zone
    2. crop that image and have the cropped preview show up on that page
    3. allow them to redo the above if they don't like it
    4. save the cropped image as the thumbnail for a post.

    The overall purpose of the page template is a form to allow the visitor to fill in key information to create a draft. I have the guts of the wp create post with thumbnail part working, but the image editing part is stuck. The approach I've tried so far is simply using the raw abilities of plupload, jcrop and gd on the front end (page template/form). I can make most of that work in bits and pieces following the examples and snippets they give, but the latest snag was the gd function imagejpeg displays raw data even though I used a call like this:

    .
    .
    imagecopyresampled( $dst_image , $src_image , $dst_x , $dst_y , $src_x , $src_y , $dst_w , $dst_h , $src_w , $src_h );
    .
    .
    .
    imagejpeg($dst_image,$img_file,$jpeg_quality);

    I thought it was supposed to "save" the cropped file. Needless to say I'm frustrated and thinking there MUST be an easier way!

    I am aware of plugins (and the amazing built in media stuff with version 3.5) that do this on the admin side, so can anyone throw me a hint (or a couple of examples) on how to leverage those function from the front end? WordPress has being doing this for years, but I can't figure out how to get at that gold mine of mature code.

    I will re-post this on stackoverflow. Thanks all!

  2. manifestcreative
    Member
    Posted 1 year ago #

    I'm interested in learning whether you came up with any solutions on this... I'd like users to be able to upload and crop their own avatars if a Gravatar is not available.

  3. RonStrilaeff
    Member
    Posted 1 year ago #

    I ended up not using the built in media code but did have to enqueue all this to load the supporting javascript into a frontend page template.

    wp_enqueue_script('jquery');
    wp_enqueue_script('plupload-handlers');
    wp_enqueue_script('jcrop');
    wp_enqueue_style('jcrop');

    Then figure out how json and ajax works to get everything to behave.

    My code is nowhere near mature or tight enough for a shareable plugin or even good enough for me to explain how it works... (I'm still learning so this is strictly in-house for that particular page/purpose, and is not even live yet.)

    I'm not aware of plugin that does the gravitar upload/crop from a front end widget or like a mini-registration or login form, but I have similar needs so I'll be digging into that in the next few months.

    In the meantime, apparently this plugin allows users to do that if you allow them to get to the user admin page.
    http://wordpress.org/extend/plugins/user-avatar/screenshots/

    glhf!

Topic Closed

This topic has been closed to new replies.

About this Topic