wp_getimagesize( string $filename, array $image_info = null ): array|false

Allows PHP’s getimagesize() to be debuggable when necessary.

Parameters

$filenamestringrequired
The file path.
$image_infoarrayoptional
Extended image information (passed by reference).

Default:null

Return

array|false Array of image information or false on failure.

Source

		'exporter_friendly_name' => __( 'WordPress Media' ),
		'callback'               => 'wp_media_personal_data_exporter',
	);

	return $exporters;
}

/**
 * Finds and exports attachments associated with an email address.
 *
 * @since 4.9.6
 *
 * @param string $email_address The attachment owner email address.
 * @param int    $page          Attachment page number.
 * @return array {
 *     An array of personal data.
 *
 *     @type array[] $data An array of personal data arrays.
 *     @type bool    $done Whether the exporter is finished.
 * }
 */
function wp_media_personal_data_exporter( $email_address, $page = 1 ) {
	// Limit us to 50 attachments at a time to avoid timing out.
	$number = 50;
	$page   = (int) $page;

	$data_to_export = array();

	$user = get_user_by( 'email', $email_address );
	if ( false === $user ) {
		return array(
			'data' => $data_to_export,
			'done' => true,
		);
	}

	$post_query = new WP_Query(
		array(
			'author'         => $user->ID,
			'posts_per_page' => $number,
			'paged'          => $page,
			'post_type'      => 'attachment',
			'post_status'    => 'any',
			'orderby'        => 'ID',
			'order'          => 'ASC',
		)
	);

	foreach ( (array) $post_query->posts as $post ) {
		$attachment_url = wp_get_attachment_url( $post->ID );

		if ( $attachment_url ) {
			$post_data_to_export = array(
				array(
					'name'  => __( 'URL' ),
					'value' => $attachment_url,
				),
			);

			$data_to_export[] = array(
				'group_id'          => 'media',
				'group_label'       => __( 'Media' ),
				'group_description' => __( 'User’s media data.' ),
				'item_id'           => "post-{$post->ID}",
				'data'              => $post_data_to_export,
			);
		}
	}

	$done = $post_query->max_num_pages <= $page;

	return array(
		'data' => $data_to_export,
		'done' => $done,
	);
}

/**
 * Adds additional default image sub-sizes.
 *
 * These sizes are meant to enhance the way WordPress displays images on the front-end on larger,
 * high-density devices. They make it possible to generate more suitable `srcset` and `sizes` attributes
 * when the users upload large images.
 *
 * The sizes can be changed or removed by themes and plugins but that is not recommended.
 * The size "names" reflect the image dimensions, so changing the sizes would be quite misleading.

Changelog

VersionDescription
6.5.0Added support for AVIF images.
5.8.0Added support for WebP images.
5.7.0Introduced.

User Contributed Notes

  1. Skip to note 2 content

    Usage (if you only have image URL):

    <?php
    $src          = 'https://example.com/path/to/image.jpg';
    $upload_dir   = wp_upload_dir();
    $image_path   = str_replace( $upload_dir[ 'baseurl' ], $upload_dir[ 'basedir' ], $src );
    $getimagesize = wp_getimagesize( $image_path );
    ?>
    
    <img <?php echo $getimagesize[3]; ?> src="<?php echo esc_url( $src ); ?>" />

    Returns array of data:

    $getimagesize[0]          = The width of the image.
    $getimagesize[1]          = The height of the image.
    $getimagesize[2]          = One of the IMAGETYPE_ constants indicating the type of the image.
    $getimagesize[3]          = A text string with the correct height="yyy" width="xxx" string that can be used directly in an IMG tag.
    $getimagesize['mime']     = The correspondent MIME type of the image. This information can be used to deliver images with the correct HTTP Content-type header.
    $getimagesize['channels'] = 3 for RGB pictures and 4 for CMYK pictures.
    $getimagesize['bits']     = The number of bits for each color.
    
    Array
    (
        [0] => 440
        [1] => 95
        [2] => 3
        [3] => width="440" height="95"
        [bits] => 8
        [mime] => image/png
    )

You must log in before being able to contribute a note or feedback.