Changeset 8612 for trunk/wp-includes/media.php
- Timestamp:
- 08/11/2008 03:54:26 AM (17 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/wp-includes/media.php
r8600 r8612 5 5 // scale down the default size of an image so it's a better fit for the editor and theme 6 6 function image_constrain_size_for_editor($width, $height, $size = 'medium') { 7 global $content_width; 7 8 8 9 if ( is_array($size) ) { … … 24 25 // if no width is set, default to the theme content width if available 25 26 } 26 else { // $size == 'full'27 // we're inserting a fullsize image into the editor. if it's a really big image we'll scale it down to fit reasonably27 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 28 29 // within the editor itself, and within the theme's content width if it's known. the user can resize it in the editor 29 30 // 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; 35 40 } 36 41 37 42 list( $max_width, $max_height ) = apply_filters( 'editor_max_image_size', array( $max_width, $max_height ), $size ); 38 43 39 44 return wp_constrain_dimensions( $width, $height, $max_width, $max_height ); 40 45 } … … 52 57 // Scale an image to fit a particular size (such as 'thumb' or 'medium'), and return an image URL, height and width. 53 58 // 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 55 61 function image_downsize($id, $size = 'medium') { 56 62 … … 61 67 $meta = wp_get_attachment_metadata($id); 62 68 $width = $height = 0; 69 $is_intermediate = false; 63 70 64 71 // plugins can use this to provide resize services … … 71 78 $width = $intermediate['width']; 72 79 $height = $intermediate['height']; 80 $is_intermediate = true; 73 81 } 74 82 elseif ( $size == 'thumbnail' ) { … … 78 86 $width = $info[0]; 79 87 $height = $info[1]; 88 $is_intermediate = true; 80 89 } 81 90 } 82 91 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 } 89 103 return false; 90 104
Note: See TracChangeset
for help on using the changeset viewer.