import { Component } from 'inferno'; const iconThumbnailSize = 96; const thumbnailSize = 256; const maxImageSize = 3000; interface PictrsImageProps { src: string; icon?: boolean; thumbnail?: boolean; nsfw?: boolean; iconOverlay?: boolean; pushup?: boolean; } export class PictrsImage extends Component { constructor(props: any, context: any) { super(props, context); } render() { return ( ); } src(format: string): string { // sample url: // http://localhost:8535/pictrs/image/file.png?thumbnail=256&format=jpg let split = this.props.src.split('/pictrs/image/'); // If theres not multiple, then its not a pictrs image if (split.length == 1) { return this.props.src; } let host = split[0]; let path = split[1]; let params = { format }; if (this.props.thumbnail) { params['thumbnail'] = thumbnailSize; } else if (this.props.icon) { params['thumbnail'] = iconThumbnailSize; } else { params['thumbnail'] = maxImageSize; } let paramsStr = `?${new URLSearchParams(params).toString()}`; let out = `${host}/pictrs/image/${path}${paramsStr}`; return out; } }