WordPress at a glance

wp_get_attachment_image_sizes() WP 1.0

Retrieves the value for an image attachment's 'sizes' attribute.

  • See: wp_calculate_image_sizes()
✈ 1 time = 0.000911s = slow | 50000 times = 30s = slow

No Hooks.

Return

String/true/false. A valid source size value for use in a 'sizes' attribute or false.

Usage

wp_get_attachment_image_sizes( $attachment_id, $size, $image_meta );
$attachment_id(int) (required)
Image attachment ID.
$size(array/string)
Image size. Accepts any valid image size, or an array of width and height values in pixels (in that order).
Default: 'medium'
$image_meta(array)
The image meta data as returned by 'wp_get_attachment_metadata()'.
Default: null

Code of wp_get_attachment_image_sizes: wp-includes/media.php VER 4.9.8

<?php
function wp_get_attachment_image_sizes( $attachment_id, $size = 'medium', $image_meta = null ) {
	if ( ! $image = wp_get_attachment_image_src( $attachment_id, $size ) ) {
		return false;
	}

	if ( ! is_array( $image_meta ) ) {
		$image_meta = wp_get_attachment_metadata( $attachment_id );
	}

	$image_src = $image[0];
	$size_array = array(
		absint( $image[1] ),
		absint( $image[2] )
	);

	return wp_calculate_image_sizes( $size_array, $image_src, $image_meta, $attachment_id );
}

Related Functions

From tag: image (not thumbnails funcs)

More from category: Images

No comments
    Hello, !     Log In . Register