Buddypress image quality or compression
-
Im searching for a function php code to adapt or compress avatars (profile, group) and covers.
I found this, but only works with WP Media and rtMedia uploads.
// Increase Image compression in WordPress function wt_handle_upload_callback( $data ) { $image_quality = 75; // Change this according to your needs $file_path = $data['file']; $image = false; switch ( $data['type'] ) { case 'image/jpeg': { $image = imagecreatefromjpeg( $file_path ); imagejpeg( $image, $file_path, $image_quality ); break; } case 'image/png': { $image = imagecreatefrompng( $file_path ); imagepng( $image, $file_path, $image_quality ); break; } case 'image/gif': { // Nothing to do here since imagegif doesn't have an 'image quality' option break; } } return $data; } add_filter( 'wp_handle_upload', 'wt_handle_upload_callback' ); add_filter( 'wp_editor_set_quality', function( $quality ) { return 75; } );
- You must be logged in to reply to this topic.