Make WordPress Core

Changeset 6952


Ignore:
Timestamp:
02/21/2008 06:00:15 AM (17 years ago)
Author:
ryan
Message:

Image size options from tellyworth. fixes #5933

Location:
trunk
Files:
1 added
5 edited

Legend:

Unmodified
Added
Removed
  • trunk/wp-admin/css/media.css

    r6876 r6952  
    110110}
    111111
     112.media-upload-form fieldset#image-size label {
     113    display: inline;
     114    margin: 0 1em 0 0;
     115}
     116
    112117.pinkynail {
    113118    max-width: 40px;
  • trunk/wp-admin/includes/image.php

    r6786 r6952  
    225225 */
    226226function wp_shrink_dimensions( $width, $height, $wmax = 128, $hmax = 96 ) {
    227     if ( $height <= $hmax && $width <= $wmax ){
    228         //Image is smaller than max
    229         return array( $width, $height);
    230     } elseif ( $width / $height > $wmax / $hmax ) {
    231         //Image Width will be greatest
    232         return array( $wmax, (int) ($height / $width * $wmax ));
    233     } else {
    234         //Image Height will be greatest
    235         return array( (int) ($width / $height * $hmax ), $hmax );
    236     }
     227    return wp_constrain_dimensions( $width, $height, $wmax, $hmax );
     228}
     229
     230// same as wp_shrink_dimensions, except the max parameters are optional.
     231// if either width or height are empty, no constraint is applied on that dimension.
     232function wp_constrain_dimensions( $current_width, $current_height, $max_width=0, $max_height=0 ) {
     233    if ( !$max_width and !$max_height )
     234        return array( $current_width, $current_height );
     235   
     236    $width_ratio = $height_ratio = 1.0;
     237   
     238    if ( $max_width > 0 && $current_width > $max_width )
     239        $width_ratio = $max_width / $current_width;
     240   
     241    if ( $max_height > 0 && $current_height > $max_height )
     242        $height_ratio = $max_height / $current_height;
     243   
     244    // the smaller ratio is the one we need to fit it to the constraining box
     245    $ratio = min( $width_ratio, $height_ratio );
     246   
     247    return array( intval($current_width * $ratio), intval($current_height * $ratio) );
    237248}
    238249
  • trunk/wp-admin/includes/media.php

    r6943 r6952  
    132132    <label for="image-align-right" id="image-align-right-label"><?php _e('Right'); ?></label>
    133133</fieldset>
     134<fieldset id="image-size">
     135    <legend><?php _e('Size'); ?></legend>
     136    <input type="radio" name="image-size" id="image-size-thumb" value="thumb" <?php if ($image_size == 'thumb') echo ' checked="checked"'; ?>/>
     137    <label for="image-size-thumb" id="image-size-thumb-label"><?php _e('Thumbnail'); ?></label>
     138    <input type="radio" name="image-size" id="image-size-medium" value="medium" <?php if ($image_size == 'medium' || !$image_size) echo ' checked="checked"'; ?>/>
     139    <label for="image-size-medium" id="image-size-medium-label"><?php _e('Medium'); ?></label>
     140    <input type="radio" name="image-size" id="image-size-full" value="full" <?php if ($image_size == 'full') echo ' checked="checked"'; ?>/>
     141    <label for="image-size-full" id="image-size-full-label"><?php _e('Full size'); ?></label>
     142</fieldset>
    134143<p>
    135144    <button name="image-add" id="image-add" class="button-ok" value="1"><?php _e('Add Image'); ?></button>
     
    175184            wp_iframe( 'image_upload_form', get_option('siteurl') . '/wp-admin/media-upload.php?type=image', $_POST, $id );
    176185        else {
    177             media_send_to_editor(get_image_send_to_editor($id, $_POST['image-alt'], $_POST['image-title'], $_POST['image-align'], $_POST['image-url']));
     186            media_send_to_editor(get_image_send_to_editor($id, $_POST['image-alt'], $_POST['image-title'], $_POST['image-align'], $_POST['image-url'], true, $_POST['image-size']));
    178187        }
    179188    }
     
    218227add_filter('async_upload_image', 'async_image_callback');
    219228
    220 // scale down the default size of an image so it's a better fit for the editor and theme
    221 function image_constrain_size_for_editor($width, $height) {
    222     // pick a reasonable default width for the image
    223     // $content_width might be set in the theme's functions.php
    224     if ( !empty($GLOBALS['content_width']) )
    225         $max_width = $GLOBALS['content_width'];
    226     else
    227         $max_width = 500;
    228 
    229     $max_width = apply_filters( 'editor_max_image_width', $max_width );
    230     $max_height = apply_filters( 'editor_max_image_height', $max_width );
    231    
    232     return wp_shrink_dimensions( $width, $height, $max_width, $max_height );
    233 }
    234 
    235 function get_image_send_to_editor($id, $alt, $title, $align, $url='', $rel = false) {
    236 
    237     $img_src = wp_get_attachment_url($id);
    238     $meta = wp_get_attachment_metadata($id);
    239 
    240     $hwstring = '';
    241     if ( isset($meta['width'], $meta['height']) ) {
    242         list( $width, $height ) = image_constrain_size_for_editor( $meta['width'], $meta['height'] );
    243         $hwstring = ' width="'.intval($width).'" height="'.intval($height).'"';
    244     }
    245 
    246     $html = '<img src="'.attribute_escape($img_src).'" alt="'.attribute_escape($alt).'" title="'.attribute_escape($title).'"'.$hwstring.' class="align-'.attribute_escape($align).'" />';
     229
     230function get_image_send_to_editor($id, $alt, $title, $align, $url='', $rel = false, $size='medium') {
     231
     232    $html = get_image_tag($id, $alt, $title, $align, $rel, $size);
    247233
    248234    $rel = $rel ? ' rel="attachment wp-att-'.attribute_escape($id).'"' : '';
    249235    if ( $url )
    250236        $html = "<a href='".attribute_escape($url)."'$rel>$html</a>";
     237    elseif ( $size == 'thumb' || $size == 'medium' )
     238        $html = '<a href="'.get_attachment_link($id).'"'.$rel.'>'.$html.'</a>';
    251239       
    252240    $html = apply_filters( 'image_send_to_editor', $html, $id, $alt, $title, $align, $url );
     
    393381    $out = <<<EOF
    394382
    395 <a href="{$image_upload_iframe_src}&TB_iframe=true&height=500&width=480" class="thickbox"><img src='images/media-button-image.gif' alt='' /></a>
     383<a href="{$image_upload_iframe_src}&TB_iframe=true&height=550&width=480" class="thickbox"><img src='images/media-button-image.gif' alt='' /></a>
    396384<a href="{$multimedia_upload_iframe_src}&TB_iframe=true&height=500&width=640" class="thickbox"><img src='images/media-button-gallery.gif' alt='' /></a>
    397385<a href="{$image_upload_iframe_src}&TB_iframe=true&height=500&width=640" class="thickbox"><img src='images/media-button-video.gif' alt='' /></a>
  • trunk/wp-admin/options-writing.php

    r6944 r6952  
    5555?>
    5656</select></td>
     57</tr>
     58</table>
     59
     60<h3><?php _e('Image sizes') ?></h3>
     61<p><?php _e('The sizes listed below determine the maximum dimensions to use when inserting an image into the body of a post.'); ?></p>
     62
     63<table class="niceblue">
     64<tr valign="top">
     65<th scope="row"><?php _e('Thumbnail size:') ?></th>
     66<td>
     67<label for="thumbnail_size_w"><?php _e('Width:'); ?></label>
     68<input name="thumbnail_size_w" type="text" id="thumbnail_size_w" value="<?php form_option('thumbnail_size_w'); ?>" size="6" />
     69<label for="thumbnail_size_h"><?php _e('Height:'); ?></label>
     70<input name="thumbnail_size_h" type="text" id="thumbnail_size_h" value="<?php form_option('thumbnail_size_h'); ?>" size="6" />
     71</td>
     72</tr>
     73<tr valign="top">
     74<th scope="row"><?php _e('Medium size:') ?></th>
     75<td>
     76<label for="medium_size_w"><?php _e('Width:'); ?></label>
     77<input name="medium_size_w" type="text" id="medium_size_w" value="<?php form_option('medium_size_w'); ?>" size="6" />
     78<label for="medium_size_h"><?php _e('Height:'); ?></label>
     79<input name="medium_size_h" type="text" id="thumbnail_size_h" value="<?php form_option('medium_size_h'); ?>" size="6" />
     80</td>
    5781</tr>
    5882</table>
  • trunk/wp-settings.php

    r6726 r6952  
    264264require (ABSPATH . WPINC . '/canonical.php');
    265265require (ABSPATH . WPINC . '/shortcodes.php');
     266require (ABSPATH . WPINC . '/media.php');
    266267
    267268if (strpos($_SERVER['PHP_SELF'], 'install.php') === false) {
Note: See TracChangeset for help on using the changeset viewer.