WordPress.org

Make WordPress Core


Ignore:
Timestamp:
12/08/2009 09:08:19 PM (11 years ago)
Author:
markjaquith
Message:

Introducing set_post_image_size(w, h, crop) so themes can register their special size/crop for canonical post images. WP will create this size/crop upon upload, so your canonical post images fit your space exactly!

File:
1 edited

Legend:

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

    r12338 r12342  
    3333 */
    3434function image_constrain_size_for_editor($width, $height, $size = 'medium') {
    35     global $content_width;
     35    global $content_width, $_wp_additional_image_sizes;
    3636
    3737    if ( is_array($size) ) {
     
    6262        if ( intval($content_width) > 0 )
    6363            $max_width = min( intval($content_width), $max_width );
     64    } elseif ( isset( $_wp_additional_image_sizes ) && count( $_wp_additional_image_sizes ) && in_array( $size, array_keys( $_wp_additional_image_sizes ) ) ) {
     65        $max_width = intval( $_wp_additional_image_sizes[$size]['width'] );
     66        $max_height = intval( $_wp_additional_image_sizes[$size]['height'] );
     67        if ( intval($content_width) > 0 )
     68            $max_width = min( intval($content_width), $max_width );
    6469    }
    6570    // $size == 'full' has no constraint
     
    168173    return false;
    169174
     175}
     176
     177/**
     178 * Registers a new image size
     179 */
     180function add_image_size( $name, $width = 0, $height = 0, $crop = FALSE ) {
     181    global $_wp_additional_image_sizes;
     182    $_wp_additional_image_sizes[$name] = array( 'width' => absint( $width ), 'height' => absint( $height ), 'crop' => !!$crop );
     183}
     184
     185/**
     186 * Registers an image size for the post image
     187 */
     188function set_post_image_size( $width = 0, $height = 0, $crop = FALSE ) {
     189    add_image_size( 'post-image', $width, $height, $crop );
    170190}
    171191
Note: See TracChangeset for help on using the changeset viewer.