Add Additional File Info (jpeg compression & file size) settings to Edit Images Screen

On the WordPress Edit Image Screen, I’d like to add a label to show the current compression level and byte file size of the image.

Any ideas how to tap into this screen and echo this data?

Read More

The current settings show:

  • Date
  • URL
  • File name
  • File type
  • Dimensions

I’d like to ad

  • File Size
  • File Compression (echo the current jpeg_quality setting)

Related posts

2 comments

  1. You can try to use the attachment_submitbox_misc_actions filter to add more info to the box. Here is an example for the filesize part:

    enter image description here

    add_action( 'attachment_submitbox_misc_actions', 'custom_fileinfo_wpse_98608' );
    function custom_fileinfo_wpse_98608(){
        global $post;
        $meta = wp_get_attachment_metadata( $post->ID );
        $upload_dir = wp_upload_dir();
        $filepath = $upload_dir['basedir']."/".$meta['file'];
        $filesize = filesize($filepath);
        ?>
        <div class="misc-pub-section">
            <?php _e( 'File Size:' ); ?> <strong><?php echo $filesize; ?> </strong> <?php _e( 'bytes' ); ?>             
        </div>
    <?php
    }
    

    The default file info is displayed with the attachment_submitbox_metadata() function through this action:

    add_action( 'attachment_submitbox_misc_actions', 'attachment_submitbox_metadata' );
    

    in the file /wp-admin/includes/media.php

  2. This 2 functions will work with custom mime uploaded files (like PSD, EPS) when meta not avaible. It also returns more then just a lot of bytes, means, 2 decimal logic unit. The 99 places the info last in the meta box.

    // Helper
    function ua_formatBytes($bytes, $precision = 2) { 
            $units = array('B', 'kB', 'mB', 'GB', 'TB'); 
            $bytes = max($bytes, 0); 
            $pow = floor(($bytes ? log($bytes) : 0) / log(1024)); 
            $pow = min($pow, count($units) - 1); 
            $bytes /= (1 << (10 * $pow)); 
    
            return round($bytes, $precision) . ' ' . $units[$pow]; 
    } 
    
    // Hooked
    function ua_admin_custom_filesize_on_edit_media_screen() {
            global $post; // $post = get_post();
            $filesize = @filesize(get_attached_file($post->ID));
    
            if ( ! empty( $filesize ) && is_numeric( $filesize ) && $filesize > 0 ) : ?>
                    <div class="misc-pub-section">
                            <?php _e( 'File size:' ); ?> <strong><?php echo ua_formatBytes( $filesize ); ?></strong>
                    </div>
            <?php
            endif;
    }
    add_action( 'attachment_submitbox_misc_actions', 'ua_admin_custom_filesize_on_edit_media_screen', 99 );
    

Comments are closed.