Make WordPress Core

Ticket #5777: image-editor-constrain-size-r6736.patch

File image-editor-constrain-size-r6736.patch, 1.9 KB (added by tellyworth, 18 years ago)
  • wordpress/wp-admin/includes/media.php

     
    182182
    183183add_filter('async_upload_image', 'async_image_callback');
    184184
     185// scale down the default size of an image so it's a better fit for the editor and theme
     186function image_constrain_size_for_editor($width, $height) {
     187        // pick a reasonable default width for the image
     188        // $content_width might be set in the theme's functions.php
     189        if ( !empty($GLOBALS['content_width']) )
     190                $max_width = $GLOBALS['content_width'];
     191        else
     192                $max_width = 500;
    185193
     194        $max_width = apply_filters( 'editor_max_image_width', $max_width );
     195        $max_height = apply_filters( 'editor_max_image_height', $max_width );
     196       
     197        return wp_shrink_dimensions( $width, $height, $max_width, $max_height );
     198}
     199
    186200function image_send_to_editor($id, $alt, $title, $align, $url='') {
    187201
    188202        $img_src = wp_get_attachment_url($id);
    189203        $meta = wp_get_attachment_metadata($id);
    190204
    191205        $hwstring = '';
    192         if ( isset($meta['width'], $meta['height']) )
    193                 $hwstring = ' width="'.intval($meta['width']).'" height="'.intval($meta['height']).'"';
     206        if ( isset($meta['width'], $meta['height']) ) {
     207                list( $width, $height ) = image_constrain_size_for_editor( $meta['width'], $meta['height'] );
     208                $hwstring = ' width="'.intval($width).'" height="'.intval($height).'"';
     209        }
    194210
    195211        $html = '<img src="'.attribute_escape($img_src).'" rel="attachment wp-att-'.attribute_escape($id).'" alt="'.attribute_escape($alt).'" title="'.attribute_escape($title).'"'.$hwstring.' class="align-'.attribute_escape($align).'" />';
    196212
    197213        if ( $url )
    198214                $html = '<a href="'.attribute_escape($url).'">'.$html.'</a>';
     215               
     216        $html = apply_filters( 'image_send_to_editor', $html, $id, $alt, $title, $align, $url );
    199217
    200218        media_send_to_editor($html);
    201219}