Make WordPress Core


Ignore:
Timestamp:
08/11/2008 03:54:26 AM (18 years ago)
Author:
ryan
Message:

Separate Large and Full image sizes. Props tellyworth. fixes #7151

File:
1 edited

Legend:

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

    r8600 r8612  
    55// scale down the default size of an image so it's a better fit for the editor and theme
    66function image_constrain_size_for_editor($width, $height, $size = 'medium') {
     7        global $content_width;
    78
    89        if ( is_array($size) ) {
    … …  
    2425                // if no width is set, default to the theme content width if available
    2526        }
    26         else { // $size == 'full'
    27                 // we're inserting a full size image into the editor.  if it's a really big image we'll scale it down to fit reasonably
     27        elseif ( $size == 'large' ) {
     28                // we're inserting a large size image into the editor.  if it's a really big image we'll scale it down to fit reasonably
    2829                // within the editor itself, and within the theme's content width if it's known.  the user can resize it in the editor
    2930                // if they wish.
    30                 if ( !empty($GLOBALS['content_width']) ) {
    31                         $max_width = $GLOBALS['content_width'];
    32                 }
    33                 else
    34                         $max_width = 500;
     31                $max_width = intval(get_option('large_size_w'));
     32                $max_height = intval(get_option('large_size_h'));
     33                if ( intval($content_width) > 0 )
     34                        $max_width = min( intval($content_width), $max_width );
     35        }
     36        // $size == 'full' has no constraint
     37        else {
     38                $max_width = $width;
     39                $max_height = $height;
    3540        }
    3641
    3742        list( $max_width, $max_height ) = apply_filters( 'editor_max_image_size', array( $max_width, $max_height ), $size );
    38 
     43       
    3944        return wp_constrain_dimensions( $width, $height, $max_width, $max_height );
    4045}
    … …  
    5257// Scale an image to fit a particular size (such as 'thumb' or 'medium'), and return an image URL, height and width.
    5358// The URL might be the original image, or it might be a resized version.  This function won't create a new resized copy, it will just return an already resized one if it exists.
    54 // returns an array($url, $width, $height)
     59// returns an array($url, $width, $height, $is_intermediate)
     60// $is_intermediate is true if $url is a resized image, false if it is the original
    5561function image_downsize($id, $size = 'medium') {
    5662
    … …  
    6167        $meta = wp_get_attachment_metadata($id);
    6268        $width = $height = 0;
     69        $is_intermediate = false;
    6370
    6471        // plugins can use this to provide resize services
    … …  
    7178                $width = $intermediate['width'];
    7279                $height = $intermediate['height'];
     80                $is_intermediate = true;
    7381        }
    7482        elseif ( $size == 'thumbnail' ) {
    … …  
    7886                        $width = $info[0];
    7987                        $height = $info[1];
     88                        $is_intermediate = true;
    8089                }
    8190        }
    8291        if ( !$width && !$height && isset($meta['width'], $meta['height']) ) {
    83                 // any other type: use the real image and constrain it
    84                 list( $width, $height ) = image_constrain_size_for_editor( $meta['width'], $meta['height'], $size );
    85         }
    86 
    87         if ( $img_url)
    88                 return array( $img_url, $width, $height );
     92                // any other type: use the real image
     93                $width = $meta['width'];
     94                $height = $meta['height'];
     95        }
     96       
     97        if ( $img_url) {
     98                // we have the actual image size, but might need to further constrain it if content_width is narrower
     99                list( $width, $height ) = image_constrain_size_for_editor( $width, $height, $size );
     100
     101                return array( $img_url, $width, $height, $is_intermediate );
     102        }
    89103        return false;
    90104
Note: See TracChangeset for help on using the changeset viewer.