Restrict media upload size by format

I'm looking for a way to restrict the size of the media when uploading (a plugin or just a function).

So I found this:

function increase_upload_size_limit( $limit ) {
  return 524288;
}
add_filter( 'upload_size_limit', 'increase_upload_size_limit' );

And it's working, but the thing is that i'd like to choose a different size restriction for a pdf than for a jpeg.

The thing that would really be perfect is to be able to choose the max size per format. And when uploading a media, it tries compressing it, and if the compression isn't able to compress enough (to be under the max size selected) then there's a message saying that this media can't be uploaded due to its size.

So if it just restrict upload size by format it will be good enough for me.

Thanks a lot!

Topic compression functions uploads media plugins Wordpress

Category Web

About

Geeks Mental is a community that publishes articles and tutorials about Web, Android, Data Science, new techniques and Linux security.