WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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?

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)
share|improve this question
Is it possible to inspect a jpg file compression? Looks like not... – brasofilo May 7 '13 at 14:23
Not that I'm aware of, but the current wordpress setting for jpeg_quality should be sufficient. – N2Mystic May 7 '13 at 19:09
up vote 3 down vote accepted

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' ); ?>             

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

share|improve this answer
+1 Works perfectly. Now I just need to figure out how to echo the site's jpeg_quality setting – N2Mystic May 7 '13 at 19:30
ok great, thanks for sharing your jpeg_quality solution. – birgire May 7 '13 at 19:42

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>
add_action( 'attachment_submitbox_misc_actions', 'ua_admin_custom_filesize_on_edit_media_screen', 99 );
share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.