Sunday, 8 September 2013

auto resize image uploaded using wp_handle_upload

auto resize image uploaded using wp_handle_upload

I wrote a simple plugin to upload an image, but it allows for any size and
displays it full size. I know wordpress has an add_image_size function
that can be used for resizing, is this what I want to use? Id like to have
a default size set that any image uploaded via this box will be resized to
(keeping aspect ratio ofcourse).
public function jo_validate_settings($plugin_options)
{
if (!empty($_FILES['jo_file_upload']['tmp_name'])) {
$override = array('test_form' => false);
$file = wp_handle_upload($_FILES['jo_file_upload'], $override);
$plugin_options['jo_file_upload'] = $file['url'];
} else {
$plugin_options['jo_file_upload'] = $this->options['jo_file_upload'];
}
Thats my code to upload the image. The display is just an echo of the
options and id. Any advice for me guys? Id like a simple solution,
something clean possibly already implemented into wordpress. All I can
find online is more advanced method that require me to write my own resize
code.

No comments:

Post a Comment