[wp-hackers] Plupload, WP 3.3 and client-side resizing

Manuel Schmalstieg webdev at ms-studio.net
Mon Jan 16 21:33:19 UTC 2012


Braydon, thank you very much for those hints. But as you say, these
paramaters don't prevent the uploading of insanely large images. I
just tested your code example, and it's actually not solving the
issue, the result is the same as when the limit is set in the WP admin
panel: a very large image (say a Canon EOS 20+ megapixel jpeg) will
still be able to cause harm.

The problem is that the WP uploader *will* be able to upload the
image, so the unaware user will think all is fine, but the server (or
the Plupload script) won't be able to downsize it. So in place of a
reduced image, it's actually the full native file in all it's glory
that gets embedded and brings the page load to a crawl.

I was really hoping that Plupload would provide some way of detecting
such a large image, before WP even attempts to downsize it.

-Manuel


On Tue, Jan 3, 2012 at 12:34 AM, Braydon <ronin at braydon.com> wrote:
> Plupload has a resize parameter that can resize images on the client-side,
> if possible. I haven't seen anything about it blocking images.
>
> Here is the parameter from their docs (
> http://www.plupload.com/documentation.php ):
>
> var uploader = new plupload.Uploader({
>        (...)
>        resize : {width : 320, height : 240, quality : 90},
>        (...)
> });
>
> On the WordPress side, there is a filter "plupload_init" to modify default
> settings. On line 1331 of /wp-admin/includes/media.php resize isn't
> currently being used.
>
> Adding this into functions.php should probably do the trick (untested):
>
> add_filter( 'plupload_init', 'my_plupload_init', 0, 1 );
>
> function my_plupload_init( $plupload_init ) {
>        $plupload_init['resize'] = array('width' =>  1024, 'height' =>
>  1024);
>        return $plupload_init;
>
> }
>
> On 01/02/2012 02:11 PM, Manuel Schmalstieg wrote:
>>
>> I am currently searching for documentation about the Plupload script
>> that was integrated into the WP core with the 3.3 release.
>>
>> My needs are the following:
>>
>> - force a size limit of 1024px width / height for picture uploads.
>> - if the picture is bigger, ask the browser for client-side downsizing.
>> - if the browser can't do it, refuse the upload and provide a
>> meaningful error message.
>>
>> I was wondering if WP 3.3 would provide a config panel for such
>> settings, a bit like the (now obsoleted) WPlupload plugin did:
>> http://wordpress.org/extend/plugins/wplupload/screenshots/
>>
>> Or can we define such things in functions.php ? Is there any
>> "official" documentation about how Plupload works in WP? Any examples
>> or "best practices"?
>>
>> Many questions. For some reason, Google didn't bring up any up-to-date
>> information.
>>
>> Any advice would be much appreciated.
>> _______________________________________________
>> wp-hackers mailing list
>> wp-hackers at lists.automattic.com
>> http://lists.automattic.com/mailman/listinfo/wp-hackers
>>
>> !DSPAM:4f022ba7211011713282792!
>>
>
> _______________________________________________
> wp-hackers mailing list
> wp-hackers at lists.automattic.com
> http://lists.automattic.com/mailman/listinfo/wp-hackers


More information about the wp-hackers mailing list