1 import { Component } from "inferno";
3 const iconThumbnailSize = 96;
4 const thumbnailSize = 256;
5 const maxImageSize = 3000;
7 interface PictrsImageProps {
13 iconOverlay?: boolean;
17 export class PictrsImage extends Component<PictrsImageProps, any> {
18 constructor(props: any, context: any) {
19 super(props, context);
25 <source srcSet={this.src("webp")} type="image/webp" />
26 <source srcSet={this.src("jpg")} type="image/jpeg" />
31 ${!this.props.icon && !this.props.iconOverlay && "img-fluid "}
33 this.props.thumbnail && !this.props.icon
34 ? "thumbnail rounded "
37 ${this.props.thumbnail && this.props.nsfw && "img-blur "}
38 ${this.props.icon && "rounded-circle img-icon mr-2 "}
39 ${this.props.iconOverlay && "ml-2 mb-0 rounded-circle avatar-overlay "}
40 ${this.props.pushup && "avatar-pushup "}
47 src(format: string): string {
49 // http://localhost:8535/pictrs/image/file.png?thumbnail=256&format=jpg
51 let split = this.props.src.split("/pictrs/image/");
53 // If theres not multiple, then its not a pictrs image
54 if (split.length == 1) {
55 return this.props.src;
61 let params = { format };
63 if (this.props.thumbnail) {
64 params["thumbnail"] = thumbnailSize;
65 } else if (this.props.icon) {
66 params["thumbnail"] = iconThumbnailSize;
68 params["thumbnail"] = maxImageSize;
71 let paramsStr = `?${new URLSearchParams(params).toString()}`;
72 let out = `${host}/pictrs/image/${path}${paramsStr}`;
78 if (this.props.icon) {
81 return this.props.alt || "";