1 import classNames from "classnames";
2 import { Component } from "inferno";
4 const iconThumbnailSize = 96;
5 const thumbnailSize = 256;
7 interface PictrsImageProps {
14 iconOverlay?: boolean;
18 export class PictrsImage extends Component<PictrsImageProps, any> {
19 constructor(props: any, context: any) {
20 super(props, context);
26 <source srcSet={this.src("webp")} type="image/webp" />
27 <source srcSet={this.props.src} />
28 <source srcSet={this.src("jpg")} type="image/jpeg" />
33 className={classNames({
34 "img-fluid": !this.props.icon && !this.props.iconOverlay,
35 banner: this.props.banner,
37 this.props.thumbnail && !this.props.icon && !this.props.banner,
38 "img-expanded slight-radius":
39 !this.props.thumbnail && !this.props.icon,
40 "img-blur": this.props.thumbnail && this.props.nsfw,
41 "rounded-circle img-icon mr-2": this.props.icon,
42 "ml-2 mb-0 rounded-circle avatar-overlay": this.props.iconOverlay,
43 "avatar-pushup": this.props.pushup,
50 src(format: string): string {
52 // http://localhost:8535/pictrs/image/file.png?thumbnail=256&format=jpg
54 let split = this.props.src.split("/pictrs/image/");
56 // If theres not multiple, then its not a pictrs image
57 if (split.length == 1) {
58 return this.props.src;
64 let params = { format };
66 if (this.props.thumbnail) {
67 params["thumbnail"] = thumbnailSize;
68 } else if (this.props.icon) {
69 params["thumbnail"] = iconThumbnailSize;
72 let paramsStr = new URLSearchParams(params).toString();
73 let out = `${host}/pictrs/image/${path}?${paramsStr}`;
79 if (this.props.icon) {
82 return this.props.alt || "";