Changeset 7263 for trunk/wp-includes/media.php
- Timestamp:
- 03/12/2008 08:10:00 AM (18 years ago)
- File:
-
- 1 edited
-
trunk/wp-includes/media.php (modified) (8 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/wp-includes/media.php
r7233 r7263 6 6 function image_constrain_size_for_editor($width, $height, $size = 'medium') { 7 7 8 if ( $size == 'thumb' ) { 8 if ( is_array($size) ) { 9 $max_width = $size[0]; 10 $max_height = $size[1]; 11 } 12 elseif ( $size == 'thumb' || $size == 'thumbnail' ) { 9 13 $max_width = intval(get_option('thumbnail_size_w')); 10 14 $max_height = intval(get_option('thumbnail_size_h')); … … 76 80 } 77 81 } 78 elseif (isset($meta['width'], $meta['height']) ) {82 if ( !$width && !$height && isset($meta['width'], $meta['height']) ) { 79 83 // any other type: use the real image and constrain it 80 84 list( $width, $height ) = image_constrain_size_for_editor( $meta['width'], $meta['height'], $size ); … … 251 255 if ( !$imagedata = wp_get_attachment_metadata( $post_id ) ) 252 256 return false; 253 254 if ( empty($imagedata['sizes'][$size]) ) 257 258 // get the best one for a specified set of dimensions 259 if ( is_array($size) && !empty($imagedata['sizes']) ) { 260 foreach ( $imagedata['sizes'] as $_size => $data ) { 261 // already cropped to width or height; so use this size 262 if ( ( $data['width'] == $size[0] && $data['height'] <= $size[1] ) || ( $data['height'] == $size[1] && $data['width'] <= $size[0] ) ) { 263 $file = $data['file']; 264 list($width, $height) = image_constrain_size_for_editor( $data['width'], $data['height'], $size ); 265 return compact( 'file', 'width', 'height' ); 266 } 267 // add to lookup table: area => size 268 $areas[$data['width'] * $data['height']] = $_size; 269 } 270 if ( !$size || !empty($areas) ) { 271 // find for the smallest image not smaller than the desired size 272 ksort($areas); 273 foreach ( $areas as $_size ) { 274 $data = $imagedata['sizes'][$_size]; 275 if ( $data['width'] >= $size[0] || $data['height'] >= $size[1] ) { 276 $file = $data['file']; 277 list($width, $height) = image_constrain_size_for_editor( $data['width'], $data['height'], $size ); 278 return compact( 'file', 'width', 'height' ); 279 } 280 } 281 } 282 } 283 284 if ( is_array($size) || empty($size) || empty($imagedata['sizes'][$size]) ) 255 285 return false; 256 286 … … 260 290 // get an image to represent an attachment - a mime icon for files, thumbnail or intermediate size for images 261 291 // returns an array (url, width, height), or false if no image is available 262 function wp_get_attachment_image_src($attachment_id, $size='thumbnail' ) {292 function wp_get_attachment_image_src($attachment_id, $size='thumbnail', $icon = false) { 263 293 264 294 // get a thumbnail or intermediate image if there is one … … 266 296 return $image; 267 297 268 if ( $ src = wp_mime_type_icon($attachment_id) ) {298 if ( $icon && $src = wp_mime_type_icon($attachment_id) ) { 269 299 $icon_dir = apply_filters( 'icon_dir', ABSPATH . WPINC . '/images/crystal' ); 270 300 $src_file = $icon_dir . '/' . basename($src); … … 277 307 278 308 // as per wp_get_attachment_image_src, but returns an <img> tag 279 function wp_get_attachment_image($attachment_id, $size='thumbnail' ) {309 function wp_get_attachment_image($attachment_id, $size='thumbnail', $icon = false) { 280 310 281 311 $html = ''; 282 $image = wp_get_attachment_image_src($attachment_id, $size );312 $image = wp_get_attachment_image_src($attachment_id, $size, $icon); 283 313 if ( $image ) { 284 314 list($src, $width, $height) = $image; 285 315 $hwstring = image_hwstring($width, $height); 316 if ( is_array($size) ) 317 $size = join('x', $size); 286 318 $html = '<img src="'.attribute_escape($src).'" '.$hwstring.'class="attachment-'.attribute_escape($size).'" />'; 287 319 } … … 323 355 324 356 foreach ( $attachments as $id => $attachment ) { 325 $link = get_the_attachment_link($id, false, array(128, 96), true);357 $link = wp_get_attachment_link($id, 'thumbnail', true); 326 358 $output .= " 327 359 <div> … … 359 391 360 392 if ( isset($attachments[$k]) ) 361 echo get_the_attachment_link($attachments[$k]->ID, true, array(128, 96), true);393 echo wp_get_attachment_link($attachments[$k]->ID, 'thumbnail', true); 362 394 } 363 395
Note: See TracChangeset
for help on using the changeset viewer.