EmbyCrackedClient/web/modules/common/imagehelper.js

1 line
11 KiB
JavaScript
Raw Normal View History

2025-06-25 11:46:04 +08:00
import skinManager from"./../skinmanager.js";function mode(array){if(!array.length)return null;var modeMap={};let maxEl=array[0],maxCount=1;for(let i=0;i<array.length;i++){var el=array[i];let newValue;null==modeMap[el]?modeMap[el]=newValue=1:(newValue=modeMap[el]+1,modeMap[el]=newValue),newValue>maxCount&&(maxEl=el,maxCount=newValue)}return maxEl}function normalizeAspect(result){return 1.555555<=result?16/9:1.133333<=result?4/3:.8333333<=result?1:2/3}function getPrimaryImageAspectRatio(items,options){var values=[],showProgramImage=options?.showCurrentProgramImage;for(let i=0,length=items.length;i<length;i++){var item=items[i];let imageItem;item=(imageItem=showProgramImage?item.CurrentProgram||item:item.ProgramInfo||item).PrimaryImageAspectRatio||0;item&&(values[values.length]=normalizeAspect(item))}return values.length?mode(values):null}function getDefaultShape(items){items=items[0];if(items)switch(items.Type){case"Movie":case"SeriesTimer":case"Timer":return"portrait";case"Episode":case"Program":case"Video":return"backdrop"}return"square"}function getShapeFromAspect(primaryImageAspectRatio){return primaryImageAspectRatio?3<=primaryImageAspectRatio?"banner":1.4<=primaryImageAspectRatio?"backdrop":1.2<primaryImageAspectRatio?"fourThree":.73<primaryImageAspectRatio?"square":"portrait":null}function getShape(items,options){let shape=null;var primaryImageAspectRatio=getPrimaryImageAspectRatio(items,options);return shape=(shape=getShapeFromAspect(primaryImageAspectRatio))||options.defaultShape||getDefaultShape(items)}function getAspectFromShape(shape,options){switch(shape){case"portrait":return{aspect:2/3,aspectCss:"2/3"};case"backdrop":return{aspect:16/9,aspectCss:"16/9"};case"square":return{aspect:1,aspectCss:"1"};case"fourThree":return{aspect:4/3,aspectCss:"4/3"};case"banner":return options.sideFooter?{aspect:1,aspectCss:"1"}:{aspect:1e3/185,aspectCss:"1000/185"};default:return console.log("Unrecognized shape: "+shape+"--"+(new Error).stack),{}}}function getImageUrl(item,apiClient,options,shape){var width=options.width,adjustForPixelRatio=options.adjustForPixelRatio;let imgUrl,imageType;if(item.ImageUrl)return imgUrl=item.ImageUrl,options.addImageSizeToUrl&&options.width&&(imgUrl+="&maxWidth="+width),{imgUrl:imgUrl,aspect:item.PrimaryImageAspectRatio};let height=null;var primaryImageAspectRatio=item.PrimaryImageAspectRatio;let forceName=!1,imageAspect;var imageTags=item.ImageTags,uiAspect=options.uiAspect,keepAnimation=options.keepImageAnimation||null,preferThumb=options.preferThumb;return preferThumb&&imageTags&&imageTags.Thumb?(imgUrl=apiClient.getImageUrl(item.Id,{type:"Thumb",maxWidth:width,tag:imageTags.Thumb,adjustForPixelRatio:adjustForPixelRatio,keepAnimation:keepAnimation}),imageAspect=16/9):(options.preferBanner||"banner"===shape)&&imageTags&&imageTags.Banner?(imgUrl=apiClient.getImageUrl(item.Id,{type:"Banner",maxWidth:width,tag:imageTags.Banner,adjustForPixelRatio:adjustForPixelRatio,keepAnimation:keepAnimation}),imageAspect=1e3/185):options.preferDisc&&imageTags&&imageTags.Disc?(imgUrl=apiClient.getImageUrl(item.Id,{type:"Disc",maxWidth:width,tag:imageTags.Disc,adjustForPixelRatio:adjustForPixelRatio,keepAnimation:keepAnimation}),imageAspect=1):options.preferLogo&&imageTags&&imageTags.Logo?(imageType="Logo",imgUrl=apiClient.getImageUrl(item.Id,{type:imageType,maxWidth:width,tag:imageTags.Logo,adjustForPixelRatio:adjustForPixelRatio,keepAnimation:keepAnimation}),imageAspect=16/9):options.preferLogo&&item.ParentLogoImageTag&&item.ParentLogoItemId?(imageType="Logo",imgUrl=apiClient.getImageUrl(item.ParentLogoItemId,{type:imageType,maxWidth:width,tag:item.ParentLogoImageTag,adjustForPixelRatio:adjustForPixelRatio,keepAnimation:keepAnimation}),imageAspect=16/9):options.showChannelLogo&&item.ChannelPrimaryImageTag&&item.ChannelId?(imgUrl=apiClient.getImageUrl(item.ChannelId,{type:"Primary",maxWidth:width,tag:item.ChannelPrimaryImageTag,adjustForPixelRatio:adjustForPixelRatio,keepAnimation:keepAnimation}),imageAspect=16/9):preferThumb&&item.ParentThumbItemId&&!1!==options.inheritThumb&&"Photo"!==item.MediaType?(imgUr