1. Home
  2. Docs
  3. UniWP 1.5
  4. Media class
  5. GetImagesInfo

GetImagesInfo

WHAT ISGet information about the images with the given IDs.
DONEReturn an array of MediaImageInfo values. Each value contains information about each found image.
ERRORReturn the WordPress system error message (see the WP Code Reference).
USED WP
METHODS
wp_get_attachment_image_src (for each image’s ID, with the given size)

_ = wpMedia.$GetImagesInfo$(%imagesID, %^size^).$Done$(%doneCallback%).$Error$(%errorCallback%).$Run$();

imagesID|array<int>
An array containing the IDs of the images to get the information from.
__
size|(string)
Default: full
One of the predefined WordPress sizes for the images: thumbnail, medium, large, full.
__
doneCallback|function
The function to call when the operation will be completed.
Note: the use of the Done() method is mandatory.
__
errorCallback|(function)
The function to call in case of error.
Note: the use of the Error() method is optional and can be omitted.

{{{#912c9a|WPReply|Data-type|Property or method description}}}
__
.GetImagesInfo()|[array<MediaImageInfo>]
Return an array of MediaImageInfo (see the GetImagesInfo() paragraph below).
__
.isOK|bool
true if everything is ok, false in case of error.
__
.isError|bool
true in case of error, false if everything is ok.
__
.error|string
The error message from the Server. It can be a string generated by WordPress through its get_error_message method (see the WP manual).
__
errorType|HttpRequest.Error Enum
The kind of error:
NONE = no error.
HTTP_ERROR = communication error.
SYSTEM_ERROR = UniWP error.
WORDPRESS_ERROR = error message from WordPress REST APIs.


MediaImageInfo

The MediaImageInfo class exposes properties for an image.

id|int
The image’s ID.
__
url|string
The full HTTP URL of the image.
__
width|int
The image’s width.
__
height|int
The image’s height.
__
size|int
The image’s size in bytes.
__
isResized|bool
Whether the image is a resized image.


GetImagesInfo()

The GetImagesInfo() method of the WPReply class returns an array of MediaImageInfo class values. Each value contains information about the found image. If an image is not found (there is no image with a given ID), an empty MediaImageInfo object is returned (the properties are empty strings or 0 values).

var myMedia = new UniWP.Media();

_ = myMedia.GetImagesInfo()
    .Done((WPReply reply) => 
    {
        if (reply.isOK) {

           var foundImgs = reply.GetImagesInfo();

           foreach (var img in foundImgs) Debug.Log("Image: " + img.url + " - " + img.size + " bytes"); 

        }
    })
    .Error((WPReply reply) => 
    {
        Debug.LogError(reply.error);
    })
    .Run()