WebMedia Conversion
A WebMedia format is a format for media (images, video, audio) that retains the original format but can resize the output to be suitable to present on a web page. You can specify size and aspect ratio.
To request a thumbnail using the declarative model you create a property of type WebMedia.
public class MyMedia : MediaItem {
[ResizeEffect(Width = 400, Height = 300)]
public WebMedia Preview { get; set; }
}
When retrieving the conversion you can get the URL of the content and the content type.
var client = ClientFactory.GetSdkClient();
var media = client.Query<MyMedia>().Take(10).ToList();
foreach (var myMedia in media) {
if (myMedia.Preview != null)
Console.WriteLine(myMedia.Preview.Url + myMedia.Preview.ContentType);
}
Depending on the content type you need to use the correct html element/player to be able to use the content. This can be calculated by ImageVault íf you populate the StorageInformation for the conversion.
[MediaItem(Populate = PopulateFields.StorageInformation)]
public class MyMedia2 : MediaItem {
[ResizeEffect(Width = 400, Height = 300)]
public WebMedia Preview { get; set; }
}
When querying this type, the DefaultEmbedElement will be populated to show the html code needed to display the content.
var media2 = client.Query<MyMedia2>().Take(10).ToList();
foreach (var myMedia2 in media2) {
if (myMedia2.Preview != null)
Console.WriteLine(myMedia2.Preview.Html);
}
If the image is an image the DefaultEmbedElement will contain a img tag with suitable attributes. If you get a content that needs a player (for instance viedeo content) you will receive the html code needed to embed a player on the page.