Changeset 7263

Show
Ignore:
Timestamp:
03/12/08 08:10:00 (6 months ago)
Author:
ryan
Message:

Image fixes from andy. see #5911

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/wp-admin/edit-attachment-rows.php

    r7262 r7263  
    4040    case 'icon': 
    4141        ?> 
    42         <td class="media-icon"><?php echo get_the_attachment_link($post->ID, false, array(48,48)); ?></td> 
     42        <td class="media-icon"><?php echo wp_get_attachment_link($post->ID, array(60, 40), false, true); ?></td> 
    4343        <?php 
    4444        // TODO 
  • trunk/wp-admin/user-edit.php

    r7259 r7263  
    158158<td> 
    159159<?php 
     160$current_color = get_user_option('admin_color'); 
     161if ( empty($current_color) ) 
     162    $current_color = 'classic'; 
    160163foreach ( $_wp_admin_css_colors as $color => $color_info ): ?> 
    161 <label class="color-option"><input name="admin_color" type="radio" value="<?php echo $color ?>" class="tog" <?php checked($color, get_user_option('admin_color')); ?> /> 
     164<label class="color-option"><input name="admin_color" type="radio" value="<?php echo $color ?>" class="tog" <?php checked($color, $current_color); ?> /> 
    162165    <table class="color-palette"> 
    163166    <tr> 
  • trunk/wp-includes/media.php

    r7233 r7263  
    66function image_constrain_size_for_editor($width, $height, $size = 'medium') { 
    77 
    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' ) { 
    913        $max_width = intval(get_option('thumbnail_size_w')); 
    1014        $max_height = intval(get_option('thumbnail_size_h')); 
     
    7680        } 
    7781    } 
    78     elseif ( isset($meta['width'], $meta['height']) ) { 
     82    if ( !$width && !$height && isset($meta['width'], $meta['height']) ) { 
    7983        // any other type: use the real image and constrain it 
    8084        list( $width, $height ) = image_constrain_size_for_editor( $meta['width'], $meta['height'], $size ); 
     
    251255    if ( !$imagedata = wp_get_attachment_metadata( $post_id ) ) 
    252256        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]) ) 
    255285        return false; 
    256286         
     
    260290// get an image to represent an attachment - a mime icon for files, thumbnail or intermediate size for images 
    261291// returns an array (url, width, height), or false if no image is available 
    262 function wp_get_attachment_image_src($attachment_id, $size='thumbnail') { 
     292function wp_get_attachment_image_src($attachment_id, $size='thumbnail', $icon = false) { 
    263293     
    264294    // get a thumbnail or intermediate image if there is one 
     
    266296        return $image; 
    267297 
    268     if ( $src = wp_mime_type_icon($attachment_id) ) { 
     298    if ( $icon && $src = wp_mime_type_icon($attachment_id) ) { 
    269299        $icon_dir = apply_filters( 'icon_dir', ABSPATH . WPINC . '/images/crystal' ); 
    270300        $src_file = $icon_dir . '/' . basename($src); 
     
    277307 
    278308// as per wp_get_attachment_image_src, but returns an <img> tag 
    279 function wp_get_attachment_image($attachment_id, $size='thumbnail') { 
     309function wp_get_attachment_image($attachment_id, $size='thumbnail', $icon = false) { 
    280310 
    281311    $html = ''; 
    282     $image = wp_get_attachment_image_src($attachment_id, $size); 
     312    $image = wp_get_attachment_image_src($attachment_id, $size, $icon); 
    283313    if ( $image ) { 
    284314        list($src, $width, $height) = $image; 
    285315        $hwstring = image_hwstring($width, $height); 
     316        if ( is_array($size) ) 
     317            $size = join('x', $size); 
    286318        $html = '<img src="'.attribute_escape($src).'" '.$hwstring.'class="attachment-'.attribute_escape($size).'" />'; 
    287319    } 
     
    323355 
    324356    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); 
    326358        $output .= " 
    327359            <div> 
     
    359391 
    360392    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); 
    362394} 
    363395 
  • trunk/wp-includes/post-template.php

    r7172 r7263  
    371371 
    372372// get an attachment page link using an image or icon if possible 
    373 function wp_get_attachment_link($id = 0, $size = 'thumbnail', $permalink = false) { 
     373function wp_get_attachment_link($id = 0, $size = 'thumbnail', $permalink = false, $icon = false) { 
    374374    $_post = & get_post( intval($id) ); 
    375375 
     
    382382    $post_title = attribute_escape($_post->post_title); 
    383383 
    384     $link_text = wp_get_attachment_image($id, $size); 
     384    $link_text = wp_get_attachment_image($id, $size, $icon); 
    385385    if ( !$link_text ) 
    386386        $link_text = $_post->post_title;