Make WordPress Core


Ignore:
Timestamp:
02/07/2008 04:22:38 AM (17 years ago)
Author:
ryan
Message:

Constrain image size when adding to editor. Props tellyworth. fixes #5777

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/wp-admin/includes/media.php

    r6726 r6747  
    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;
     193
     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}
    185199
    186200function image_send_to_editor($id, $alt, $title, $align, $url='') {
     
    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).'" />';
     
    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);
Note: See TracChangeset for help on using the changeset viewer.