Make WordPress Core


Ignore:
Timestamp:
03/02/2008 08:17:30 PM (16 years ago)
Author:
ryan
Message:

Remove trailing whites.

File:
1 edited

Legend:

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

    r7043 r7130  
    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    
     7
    88    if ( $size == 'thumb' ) {
    99        $max_width = intval(get_option('thumbnail_size_w'));
     
    3434
    3535    list( $max_width, $max_height ) = apply_filters( 'editor_max_image_size', array( $max_width, $max_height ), $size );
    36    
     36
    3737    return wp_constrain_dimensions( $width, $height, $max_width, $max_height );
    3838}
     
    5252// returns an array($url, $width, $height)
    5353function image_downsize($id, $size = 'medium') {
    54    
     54
    5555    $img_url = wp_get_attachment_url($id);
    5656    $meta = wp_get_attachment_metadata($id);
    5757    $width = $height = 0;
    58    
     58
    5959    // plugins can use this to provide resize services
    6060    if ( $out = apply_filters('image_downsize', false, $id, $size) )
    6161        return $out;
    62    
     62
    6363    if ( $size == 'thumb' ) {
    6464        // thumbnail: use the thumb as the displayed image, and constrain based on its dimensions
     
    7575        list( $width, $height ) = image_constrain_size_for_editor( $meta['width'], $meta['height'], $size );
    7676    }
    77    
     77
    7878    return array( $img_url, $width, $height );
    79    
     79
    8080}
    8181
     
    9898    if ( !$max_width and !$max_height )
    9999        return array( $current_width, $current_height );
    100    
     100
    101101    $width_ratio = $height_ratio = 1.0;
    102    
     102
    103103    if ( $max_width > 0 && $current_width > $max_width )
    104104        $width_ratio = $max_width / $current_width;
    105    
     105
    106106    if ( $max_height > 0 && $current_height > $max_height )
    107107        $height_ratio = $max_height / $current_height;
    108    
     108
    109109    // the smaller ratio is the one we need to fit it to the constraining box
    110110    $ratio = min( $width_ratio, $height_ratio );
    111    
     111
    112112    return array( intval($current_width * $ratio), intval($current_height * $ratio) );
    113113}
     
    116116// if $crop is true, the largest matching central portion of the image will be cropped out and resized to the required size
    117117function image_resize_dimensions($orig_w, $orig_h, $dest_w, $dest_h, $crop=false) {
    118    
     118
    119119    if ($orig_w <= 0 || $orig_h <= 0)
    120120        return false;
     
    122122    if ($dest_w <= 0 && $dest_h <= 0)
    123123        return false;
    124    
     124
    125125    if ( $crop ) {
    126126        // crop the largest possible portion of the original image that we can size to $dest_w x $dest_h
     
    136136
    137137        $size_ratio = max($new_w / $orig_w, $new_h / $orig_h);
    138        
     138
    139139        $crop_w = ceil($new_w / $size_ratio);
    140140        $crop_h = ceil($new_h / $size_ratio);
     
    147147        $crop_w = $orig_w;
    148148        $crop_h = $orig_h;
    149        
     149
    150150        $s_x = 0;
    151151        $s_y = 0;
    152        
     152
    153153        list( $new_w, $new_h ) = wp_constrain_dimensions( $orig_w, $orig_h, $dest_w, $dest_h );
    154154    }
    155    
     155
    156156    // if the resulting image would be the same size or larger we don't want to resize it
    157157    if ($new_w >= $orig_w && $new_h >= $orig_h)
     
    176176        return $dims;
    177177    list($dst_x, $dst_y, $src_x, $src_y, $dst_w, $dst_h, $src_w, $src_h) = $dims;
    178    
     178
    179179    $newimage = imagecreatetruecolor( $dst_w, $dst_h);
    180180
Note: See TracChangeset for help on using the changeset viewer.