(req, img)
| 735 | } |
| 736 | |
| 737 | function onUseAsThumbnailClick(req, img) { |
| 738 | let scale = 1 |
| 739 | let targetWidth = img.naturalWidth |
| 740 | let targetHeight = img.naturalHeight |
| 741 | let resize = false |
| 742 | onUseAsThumbnailClick.img = img |
| 743 | |
| 744 | if (typeof onUseAsThumbnailClick.croppr == "undefined") { |
| 745 | onUseAsThumbnailClick.croppr = new Croppr("#use-as-thumb-image", { |
| 746 | aspectRatio: 1, |
| 747 | minSize: [384, 384, "px"], |
| 748 | startSize: [512, 512, "px"], |
| 749 | returnMode: "real", |
| 750 | }) |
| 751 | } |
| 752 | |
| 753 | if (img.naturalWidth > img.naturalHeight) { |
| 754 | if (img.naturalWidth > 768) { |
| 755 | scale = 768 / img.naturalWidth |
| 756 | targetWidth = 768 |
| 757 | targetHeight = (img.naturalHeight * scale) >>> 0 |
| 758 | resize = true |
| 759 | } |
| 760 | } else { |
| 761 | if (img.naturalHeight > 768) { |
| 762 | scale = 768 / img.naturalHeight |
| 763 | targetHeight = 768 |
| 764 | targetWidth = (img.naturalWidth * scale) >>> 0 |
| 765 | resize = true |
| 766 | } |
| 767 | } |
| 768 | |
| 769 | onUseAsThumbnailClick.croppr.options.minSize = { width: (384 * scale) >>> 0, height: (384 * scale) >>> 0 } |
| 770 | onUseAsThumbnailClick.croppr.options.startSize = { width: (512 * scale) >>> 0, height: (512 * scale) >>> 0 } |
| 771 | |
| 772 | if (resize) { |
| 773 | const canvas = document.createElement("canvas") |
| 774 | canvas.width = targetWidth |
| 775 | canvas.height = targetHeight |
| 776 | const ctx = canvas.getContext("2d") |
| 777 | ctx.drawImage(img, 0, 0, targetWidth, targetHeight) |
| 778 | |
| 779 | onUseAsThumbnailClick.croppr.setImage(canvas.toDataURL("image/png")) |
| 780 | } else { |
| 781 | onUseAsThumbnailClick.croppr.setImage(img.src) |
| 782 | } |
| 783 | |
| 784 | useAsThumbSelect.innerHTML = "" |
| 785 | |
| 786 | if ("use_embeddings_model" in req) { |
| 787 | let embeddings = req.use_embeddings_model.map((e) => e.split("/").pop()) |
| 788 | |
| 789 | let embOptions = document.createElement("optgroup") |
| 790 | embOptions.label = "Embeddings" |
| 791 | embOptions.replaceChildren( |
| 792 | ...embeddings.map((e) => { |
| 793 | let option = document.createElement("option") |
| 794 | option.innerText = e |
no test coverage detected