mirror of
https://github.com/gosticks/wordpress-develop.git
synced 2026-12-06 12:51:58 +00:00
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!
git-svn-id: https://develop.svn.wordpress.org/trunk@12342 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
+21
-1
@@ -32,7 +32,7 @@
|
||||
* @return array Width and height of what the result image should resize to.
|
||||
*/
|
||||
function image_constrain_size_for_editor($width, $height, $size = 'medium') {
|
||||
global $content_width;
|
||||
global $content_width, $_wp_additional_image_sizes;
|
||||
|
||||
if ( is_array($size) ) {
|
||||
$max_width = $size[0];
|
||||
@@ -61,6 +61,11 @@ function image_constrain_size_for_editor($width, $height, $size = 'medium') {
|
||||
$max_height = intval(get_option('large_size_h'));
|
||||
if ( intval($content_width) > 0 )
|
||||
$max_width = min( intval($content_width), $max_width );
|
||||
} elseif ( isset( $_wp_additional_image_sizes ) && count( $_wp_additional_image_sizes ) && in_array( $size, array_keys( $_wp_additional_image_sizes ) ) ) {
|
||||
$max_width = intval( $_wp_additional_image_sizes[$size]['width'] );
|
||||
$max_height = intval( $_wp_additional_image_sizes[$size]['height'] );
|
||||
if ( intval($content_width) > 0 )
|
||||
$max_width = min( intval($content_width), $max_width );
|
||||
}
|
||||
// $size == 'full' has no constraint
|
||||
else {
|
||||
@@ -169,6 +174,21 @@ function image_downsize($id, $size = 'medium') {
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Registers a new image size
|
||||
*/
|
||||
function add_image_size( $name, $width = 0, $height = 0, $crop = FALSE ) {
|
||||
global $_wp_additional_image_sizes;
|
||||
$_wp_additional_image_sizes[$name] = array( 'width' => absint( $width ), 'height' => absint( $height ), 'crop' => !!$crop );
|
||||
}
|
||||
|
||||
/**
|
||||
* Registers an image size for the post image
|
||||
*/
|
||||
function set_post_image_size( $width = 0, $height = 0, $crop = FALSE ) {
|
||||
add_image_size( 'post-image', $width, $height, $crop );
|
||||
}
|
||||
|
||||
/**
|
||||
* An <img src /> tag for an image attachment, scaling it down if requested.
|
||||
*
|
||||
|
||||
Reference in New Issue
Block a user