Changeset 27472 for trunk/src/wp-includes/media.php
- Timestamp:
- 03/08/2014 06:13:27 AM (13 years ago)
- File:
-
- 1 edited
-
trunk/src/wp-includes/media.php (modified) (4 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/wp-includes/media.php
r27445 r27472 184 184 * Register a new image size. 185 185 * 186 * Cropping behavior for the image size is dependent on the value of $crop: 187 * 1. If false (default), images will be scaled, not cropped. 188 * 2. If an array in the form of array( x_crop_position, y_crop_position ): 189 * - x_crop_position accepts 'left' 'center', or 'right'. 190 * - y_crop_position accepts 'top', 'center', or 'bottom'. 191 * Images will be cropped to the specified dimensions within the defined crop area. 192 * 3. If true, images will be cropped to the specified dimensions using center positions. 193 * 186 194 * @since 2.9.0 187 195 * 188 * @param string $name The image size name. 189 * @param int $width The image's width. 190 * @param int $height The image's width. 191 * @param bool $width Whether to crop the image to fit the dimensions. Default false. 196 * @param string $name Image size identifier. 197 * @param int $width Image width in pixels. 198 * @param int $height Image height in pixels. 199 * @param bool|array $crop Optional. Whether to crop images to specified height and width or resize. 200 * An array can specify positioning of the crop area. Default false. 201 * @return bool|array False, if no image was created. Metadata array on success. 192 202 */ 193 203 function add_image_size( $name, $width = 0, $height = 0, $crop = false ) { 194 204 global $_wp_additional_image_sizes; 205 195 206 $_wp_additional_image_sizes[ $name ] = array( 196 207 'width' => absint( $width ), 197 208 'height' => absint( $height ), 198 'crop' => (bool)$crop,209 'crop' => $crop, 199 210 ); 200 211 } … … 234 245 235 246 /** 236 * Registers an image size for the post thumbnail 247 * Registers an image size for the post thumbnail. 237 248 * 238 249 * @since 2.9.0 250 * @see add_image_size() for details on cropping behavior. 251 * 252 * @param int $width Image width in pixels. 253 * @param int $height Image height in pixels. 254 * @param bool|array $crop Optional. Whether to crop images to specified height and width or resize. 255 * An array can specify positioning of the crop area. Default false. 256 * @return bool|array False, if no image was created. Metadata array on success. 239 257 */ 240 258 function set_post_thumbnail_size( $width = 0, $height = 0, $crop = false ) { … … 343 361 344 362 /** 345 * Retrieve calculated resized dimensions for use in WP_Image_Editor. 346 * 347 * Calculate dimensions and coordinates for a resized image that fits within a 348 * specified width and height. If $crop is true, the largest matching central 349 * portion of the image will be cropped out and resized to the required size. 363 * Retrieve calculated resize dimensions for use in WP_Image_Editor. 364 * 365 * Calculates dimensions and coordinates for a resized image that fits 366 * within a specified width and height. 367 * 368 * Cropping behavior is dependent on the value of $crop: 369 * 1. If false (default), images will not be cropped. 370 * 2. If an array in the form of array( x_crop_position, y_crop_position ): 371 * - x_crop_position accepts 'left' 'center', or 'right'. 372 * - y_crop_position accepts 'top', 'center', or 'bottom'. 373 * Images will be cropped to the specified dimensions within the defined crop area. 374 * 3. If true, images will be cropped to the specified dimensions using center positions. 350 375 * 351 376 * @since 2.5.0 352 * @uses apply_filters() Calls 'image_resize_dimensions' on $orig_w, $orig_h, $dest_w, $dest_h and 353 * $crop to provide custom resize dimensions. 354 * 355 * @param int $orig_w Original width. 356 * @param int $orig_h Original height. 357 * @param int $dest_w New width. 358 * @param int $dest_h New height. 359 * @param bool $crop Optional, default is false. Whether to crop image or resize. 360 * @return bool|array False on failure. Returned array matches parameters for imagecopyresampled() PHP function. 377 * @uses apply_filters() Calls 'image_resize_dimensions' on $orig_w, $orig_h, $dest_w, 378 * $dest_h and $crop to provide custom resize dimensions. 379 * 380 * @param int $orig_w Original width in pixels. 381 * @param int $orig_h Original height in pixels. 382 * @param int $dest_w New width in pixels. 383 * @param int $dest_h New height in pixels. 384 * @param bool|array $crop Optional. Whether to crop image to specified height and width or resize. 385 * An array can specify positioning of the crop area. Default false. 386 * @return bool|array False on failure. Returned array matches parameters for `imagecopyresampled()`. 361 387 */ 362 388 function image_resize_dimensions($orig_w, $orig_h, $dest_w, $dest_h, $crop = false) { … … 392 418 $crop_h = round($new_h / $size_ratio); 393 419 394 $s_x = floor( ($orig_w - $crop_w) / 2 ); 395 $s_y = floor( ($orig_h - $crop_h) / 2 ); 420 if ( ! is_array( $crop ) || count( $crop ) !== 2 ) { 421 $crop = array( 'center', 'center' ); 422 } 423 424 list( $x, $y ) = $crop; 425 426 if ( 'left' === $x ) { 427 $s_x = 0; 428 } elseif ( 'right' === $x ) { 429 $s_x = $orig_w - $crop_w; 430 } else { 431 $s_x = floor( ( $orig_w - $crop_w ) / 2 ); 432 } 433 434 if ( 'top' === $y ) { 435 $s_y = 0; 436 } elseif ( 'bottom' === $y ) { 437 $s_y = $orig_h - $crop_h; 438 } else { 439 $s_y = floor( ( $orig_h - $crop_h ) / 2 ); 440 } 396 441 } else { 397 442 // don't crop, just resize using $dest_w x $dest_h as a maximum bounding box
Note:
See TracChangeset
for help on using the changeset viewer.
![(please configure the [header_logo] section in trac.ini)](/chrome/site/your_project_logo.png)