Jump to content

How to get an image url that is suitable to put in a <img src


Recommended Posts

Posted

I am moving some code from JS that currently runs inside a js page.

The current code is

var serverId = "...."; // a valid server Id 
var imageid = "....."; // a valid image id
var imageUrl = ApiClient.getImageUrl( imageId, { type: "Primary", quality: 90 } )

return "<<a is="emby-linkbutton" href="/item?id=` + imageId + `&serverId=` + serverId + `"><img src="` + imageUrl + `" height="200px" alt="` + v.Name + `" /></a>`;

I am trying to get the same exact url from C# function calls.  I have access to all the globals created during the service construction.

Thanks in advance

Scott

 

HawkXP71
Posted

Solved.. Not sure if its the ONLY solution, I would love an answer from @softworkzor @Luke

string itemid = ....;

BaseItem item = = _libraryManager.GetItemById(itemid);
ImageType imageType = ImageType.Primary; // or whichever image type you want
int imageIndex = 0;
int quality = 90;

var imageType = Image.Primary;
if ( !item.HasImage( imageType, 0 ) )
	return null;

var imageInfo = item.GetImageInfo(imageType, imageIndex );
if ( imageInfo == null )
	return null;

var imageTag = imageInfo?.DateModified.Ticks.ToString();
var imageUrl = $"/emby/Items/{item.Id}/Images/{imageType}?maxWidth={maxWidth}&quality={quality}&tag={imageTag}";

 

Posted

That will work.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...