/// <summary> /// Builds the relative url for the specified image. /// </summary> public string BuildUrl(string virtualPath, int?width, int?height) { if (string.IsNullOrWhiteSpace(virtualPath)) { virtualPath = _defaultImagePlaceHolder; } else { virtualPath = RemoveSlug(virtualPath); } var customer = new Cloudinary(_cloudinaryRemoteAccount); var transformation = new Transformation(); if (width.HasValue) { transformation = transformation.Width(width); } if (height.HasValue) { transformation = transformation.Height(height); } transformation = transformation.Crop("fill").Gravity("faces:center").DefaultImage(_defaultImagePlaceHolder); return(customer.Api.UrlImgUp.CSubDomain(true).UseRootPath(true).Transform(transformation).BuildUrl(virtualPath)); }
public void TestVideoTagWithTransformation() { var transformation = new Transformation().VideoCodec("codec", "h264").AudioCodec("acc").StartOffset(3); var expectedUrl = TestConstants.DefaultVideoUpPath + $"ac_acc,so_3.0,vc_h264/{SOURCE_MOVIE}"; var expectedTag = "<video height='100' poster='{0}.jpg' src='{0}.mp4' width='200'></video>"; expectedTag = String.Format(expectedTag, expectedUrl); var actualTag = m_api.UrlVideoUp.Transform(transformation).SourceTypes(new string[] { "mp4" }) .BuildVideoTag(SOURCE_MOVIE, "html_height=100", "html_width=200").ToString(); Assert.AreEqual(expectedTag, actualTag); expectedTag = "<video height='100' poster='{0}.jpg' width='200'>" + "<source src='{0}.webm' type='video/webm'>" + "<source src='{0}.mp4' type='video/mp4'>" + "<source src='{0}.ogv' type='video/ogg'>" + "</video>"; expectedTag = String.Format(expectedTag, expectedUrl); actualTag = m_api.UrlVideoUp.Transform(transformation) .BuildVideoTag(SOURCE_MOVIE, new StringDictionary() { { "html_height", "100" }, { "html_width", "200" } }) .ToString(); Assert.AreEqual(expectedTag, actualTag); transformation.Width(250); expectedUrl = TestConstants.DefaultVideoUpPath + $"ac_acc,so_3.0,vc_h264,w_250/{SOURCE_MOVIE}"; expectedTag = "<video poster='{0}.jpg' width='250'>" + "<source src='{0}.webm' type='video/webm'>" + "<source src='{0}.mp4' type='video/mp4'>" + "<source src='{0}.ogv' type='video/ogg'>" + "</video>"; expectedTag = String.Format(expectedTag, expectedUrl); actualTag = m_api.UrlVideoUp.Transform(transformation) .BuildVideoTag(SOURCE_MOVIE).ToString(); Assert.AreEqual(expectedTag, actualTag); transformation.Crop("fit"); expectedUrl = TestConstants.DefaultVideoUpPath + $"ac_acc,c_fit,so_3.0,vc_h264,w_250/{SOURCE_MOVIE}"; expectedTag = "<video poster='{0}.jpg'>" + "<source src='{0}.webm' type='video/webm'>" + "<source src='{0}.mp4' type='video/mp4'>" + "<source src='{0}.ogv' type='video/ogg'>" + "</video>"; expectedTag = String.Format(expectedTag, expectedUrl); actualTag = m_api.UrlVideoUp.Transform(transformation) .BuildVideoTag(SOURCE_MOVIE).ToString(); Assert.AreEqual(expectedTag, actualTag); }
/// <summary> /// Get a endpoint to access the thumbnail picture. /// </summary> /// <param name="blobName">Virtual blob name.</param> /// <param name="label">A readable label to associate with the thumbnail.</param> /// <param name="width">The expected width or null for the full size.</param> /// <param name="height">The expected height or null for the full size.</param> /// <returns>A <see cref="Uri"/> pointing to the thumbnail picture.</returns> public Uri GetThumbEndpoint(string blobName, string label, int?width = null, int?height = null) { var blobInfo = BlobInfo.FromName(blobName); if (blobInfo == null) { return(null); } width = width ?? 0; height = height ?? 0; var transformation = new Transformation(); if (width > 0 && height > 0) { transformation = transformation.Width(width); transformation = transformation.Height(height); } else if (width > 0 || height > 0) { if (width > 0) { transformation = transformation.Width(width); } if (height > 0) { transformation = transformation.Height(height); } } transformation = transformation.Crop("fill"); transformation = transformation.Gravity("faces:center"); return(GetThumbEndpoint(blobName, label, true, transformation)); }
public void TestVideoTagWithTransformation() { var transformation = new Transformation().VideoCodec("codec", "h264").AudioCodec("acc").StartOffset(3); var expectedUrl = m_defaultVideoUpPath + "ac_acc,so_3.0,vc_h264/movie"; var expectedTag = "<video height='100' poster='{0}.jpg' src='{0}.mp4' width='200'></video>"; expectedTag = String.Format(expectedTag, expectedUrl); var actualTag = m_api.UrlVideoUp.Transform(transformation).SourceTypes(new string[] { "mp4" }) .BuildVideoTag("movie", "html_height=100", "html_width=200").ToString(); Assert.AreEqual(expectedTag, actualTag); expectedTag = "<video height='100' poster='{0}.jpg' width='200'>" + "<source src='{0}.webm' type='video/webm'>" + "<source src='{0}.mp4' type='video/mp4'>" + "<source src='{0}.ogv' type='video/ogg'>" + "</video>"; expectedTag = String.Format(expectedTag, expectedUrl); actualTag = m_api.UrlVideoUp.Transform(transformation) .BuildVideoTag("movie", new StringDictionary() { { "html_height", "100" }, { "html_width", "200" } }) .ToString(); Assert.AreEqual(expectedTag, actualTag); transformation.Width(250); expectedUrl = m_defaultVideoUpPath + "ac_acc,so_3.0,vc_h264,w_250/movie"; expectedTag = "<video poster='{0}.jpg' width='250'>" + "<source src='{0}.webm' type='video/webm'>" + "<source src='{0}.mp4' type='video/mp4'>" + "<source src='{0}.ogv' type='video/ogg'>" + "</video>"; expectedTag = String.Format(expectedTag, expectedUrl); actualTag = m_api.UrlVideoUp.Transform(transformation) .BuildVideoTag("movie").ToString(); Assert.AreEqual(expectedTag, actualTag); transformation.Crop("fit"); expectedUrl = m_defaultVideoUpPath + "ac_acc,c_fit,so_3.0,vc_h264,w_250/movie"; expectedTag = "<video poster='{0}.jpg'>" + "<source src='{0}.webm' type='video/webm'>" + "<source src='{0}.mp4' type='video/mp4'>" + "<source src='{0}.ogv' type='video/ogg'>" + "</video>"; expectedTag = String.Format(expectedTag, expectedUrl); actualTag = m_api.UrlVideoUp.Transform(transformation) .BuildVideoTag("movie").ToString(); Assert.AreEqual(expectedTag, actualTag); }