| 1334 | | $base_url = str_replace( wp_basename( $attachment_url ), '', $attachment_url ); |
| | 1334 | $possible_sizes = apply_filters( 'image_size_names_choose', array( |
| | 1335 | 'thumbnail' => __('Thumbnail'), |
| | 1336 | 'medium' => __('Medium'), |
| | 1337 | 'large' => __('Large'), |
| | 1338 | 'full' => __('Full Size'), |
| | 1339 | ) ); |
| | 1340 | unset( $possible_sizes['full'] ); |
| 1336 | | if ( isset( $meta['sizes'] ) ) { |
| 1337 | | foreach ( $meta['sizes'] as $slug => $size ) { |
| 1338 | | $sizes[ $slug ] = array( |
| 1339 | | 'height' => $size['height'], |
| 1340 | | 'width' => $size['width'], |
| 1341 | | 'url' => $base_url . $size['file'], |
| 1342 | | 'orientation' => $size['height'] > $size['width'] ? 'portrait' : 'landscape', |
| | 1342 | // Loop through all potential sizes that may be chosen. Try to do this with some efficiency. |
| | 1343 | // First: run the image_downsize filter. If it returns something, we can use its data. |
| | 1344 | // If the filter does not return something, then image_downsize() is just an expensive |
| | 1345 | // way to check the image metadata, which we do second. |
| | 1346 | foreach ( $possible_sizes as $size => $label ) { |
| | 1347 | if ( $downsize = apply_filters( 'image_downsize', false, $attachment->ID, $size ) ) { |
| | 1348 | if ( ! $downsize[3] ) |
| | 1349 | continue; |
| | 1350 | $sizes[ $size ] = array( |
| | 1351 | 'height' => $downsize[2], |
| | 1352 | 'width' => $downsize[1], |
| | 1353 | 'url' => $downsize[0], |
| | 1354 | 'orientation' => $downsize[2] > $downsize[1] ? 'portrait' : 'landscape', |
| | 1356 | } elseif ( isset( $meta['sizes'][ $size ] ) ) { |
| | 1357 | if ( ! isset( $base_url ) ) |
| | 1358 | $base_url = str_replace( wp_basename( $attachment_url ), '', $attachment_url ); |
| | 1359 | |
| | 1360 | // Nothing from the filter, so consult image metadata if we have it. |
| | 1361 | $size_meta = $meta['sizes'][ $size ]; |
| | 1362 | $sizes[ $size ] = array( |
| | 1363 | 'height' => $size_meta['height'], |
| | 1364 | 'width' => $size_meta['width'], |
| | 1365 | 'url' => $base_url . $size_meta['file'], |
| | 1366 | 'orientation' => $size_meta['height'] > $size_meta['width'] ? 'portrait' : 'landscape', |
| | 1367 | ); |