Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
be94ba0520 | ||
|
|
29d437fb62 | ||
|
|
649521f7b4 | ||
|
|
4f3ed9ace8 |
No files matched your search
@@ -37,14 +37,14 @@ export class SubjectDetector {
|
||||
|
||||
/** Detections in `file` (any JPEG/PNG), upright, as fractions of the photo. */
|
||||
async detect(file: string | Buffer): Promise<Detections> {
|
||||
const img = sharp(file).rotate();
|
||||
const img = sharp(file, { failOn: "none" }).rotate();
|
||||
const meta = await img.metadata();
|
||||
const width = meta.autoOrient?.width ?? meta.width ?? 1;
|
||||
const height = meta.autoOrient?.height ?? meta.height ?? 1;
|
||||
const scale = Math.min(SIZE / width, SIZE / height);
|
||||
const rw = Math.round(width * scale);
|
||||
const rh = Math.round(height * scale);
|
||||
const { data } = await sharp(file)
|
||||
const { data } = await sharp(file, { failOn: "none" })
|
||||
.rotate()
|
||||
.resize(rw, rh, { fit: "fill" })
|
||||
.removeAlpha()
|
||||
@@ -131,7 +131,7 @@ function nms(list: Raw[], threshold = 0.45): Detection[] {
|
||||
async function addSharpness(file: string | Buffer, people: Detection[]): Promise<void> {
|
||||
if (!people.length) return;
|
||||
const W = 1024;
|
||||
const { data, info } = await sharp(file).rotate().resize({ width: W }).greyscale().raw().toBuffer({ resolveWithObject: true });
|
||||
const { data, info } = await sharp(file, { failOn: "none" }).rotate().resize({ width: W }).greyscale().raw().toBuffer({ resolveWithObject: true });
|
||||
const H = info.height;
|
||||
const values = people.map((p) => {
|
||||
const x0 = Math.max(1, Math.floor(p.x0 * W));
|
||||
|
||||
@@ -260,12 +260,15 @@ export class IngestService {
|
||||
private async makeDerivatives(orgId: string, sha256: string, storageKey: string): Promise<{ width: number; height: number }> {
|
||||
const { storage } = this.deps;
|
||||
const source = storage.resolve(storageKey);
|
||||
const meta = await sharp(source).metadata();
|
||||
// A truncated upload (interrupted FTP) still has a usable image: decode what is there
|
||||
// instead of failing the whole photo, as Photo Mechanic does. Genuinely unreadable
|
||||
// files still throw below (no width/height).
|
||||
const meta = await sharp(source, { failOn: "none" }).metadata();
|
||||
if (!meta.width || !meta.height) throw new Error("not a readable image");
|
||||
const rotated = (meta.orientation ?? 1) >= 5;
|
||||
for (const variant of ["thumb", "preview"] as const) {
|
||||
const side = VARIANT_SIZE[variant];
|
||||
const data = await sharp(source)
|
||||
const data = await sharp(source, { failOn: "none" })
|
||||
.rotate()
|
||||
.resize({ width: side, height: side, fit: "inside", withoutEnlargement: true })
|
||||
.jpeg({ quality: variant === "thumb" ? 80 : 88, mozjpeg: true })
|
||||
|
||||
@@ -69,7 +69,7 @@ export function numberBoxes(face: Box, width: number, height: number): { region:
|
||||
* sharp as the photo has it; the model scales it itself).
|
||||
*/
|
||||
export async function cropJpeg(original: string, box: Box, size = 512): Promise<Buffer> {
|
||||
const img = sharp(original).rotate();
|
||||
const img = sharp(original, { failOn: "none" }).rotate();
|
||||
const meta = await img.metadata();
|
||||
const w = meta.autoOrient?.width ?? meta.width ?? 1;
|
||||
const h = meta.autoOrient?.height ?? meta.height ?? 1;
|
||||
@@ -77,7 +77,7 @@ export async function cropJpeg(original: string, box: Box, size = 512): Promise<
|
||||
const top = Math.round(box.y0 * h);
|
||||
const width = Math.max(1, Math.min(w - left, Math.round((box.x1 - box.x0) * w)));
|
||||
const height = Math.max(1, Math.min(h - top, Math.round((box.y1 - box.y0) * h)));
|
||||
return sharp(original).rotate().extract({ left, top, width, height }).resize({ width: size, height: size, fit: "inside", withoutEnlargement: true }).jpeg({ quality: 92 }).toBuffer();
|
||||
return sharp(original, { failOn: "none" }).rotate().extract({ left, top, width, height }).resize({ width: size, height: size, fit: "inside", withoutEnlargement: true }).jpeg({ quality: 92 }).toBuffer();
|
||||
}
|
||||
|
||||
/** A photo decoded once, small: enough to tell the colour of a kit. */
|
||||
@@ -89,7 +89,7 @@ export interface SmallImage {
|
||||
}
|
||||
|
||||
export async function smallImage(original: string, side = 512): Promise<SmallImage> {
|
||||
const { data, info } = await sharp(original).rotate().resize(side, side, { fit: "inside" }).removeAlpha().raw().toBuffer({ resolveWithObject: true });
|
||||
const { data, info } = await sharp(original, { failOn: "none" }).rotate().resize(side, side, { fit: "inside" }).removeAlpha().raw().toBuffer({ resolveWithObject: true });
|
||||
return { data, width: info.width, height: info.height, channels: info.channels };
|
||||
}
|
||||
|
||||
|
||||
@@ -37,7 +37,7 @@ export class JerseyModel {
|
||||
/** Reads the number in `box` (fractions of the upright photo). `number` is null when it can't be read. */
|
||||
async read(original: string, box: Box): Promise<JerseyReading> {
|
||||
const { size, mean, std, letterbox, labels } = this.meta;
|
||||
const img = sharp(original).rotate();
|
||||
const img = sharp(original, { failOn: "none" }).rotate();
|
||||
const m = await img.metadata();
|
||||
const w = m.autoOrient?.width ?? m.width ?? 1;
|
||||
const h = m.autoOrient?.height ?? m.height ?? 1;
|
||||
@@ -45,7 +45,7 @@ export class JerseyModel {
|
||||
const top = Math.round(box.y0 * h);
|
||||
const width = Math.max(1, Math.min(w - left, Math.round((box.x1 - box.x0) * w)));
|
||||
const height = Math.max(1, Math.min(h - top, Math.round((box.y1 - box.y0) * h)));
|
||||
const { data } = await sharp(original)
|
||||
const { data } = await sharp(original, { failOn: "none" })
|
||||
.rotate()
|
||||
.extract({ left, top, width, height })
|
||||
.resize({ width: size, height: size, fit: "contain", background: { r: letterbox, g: letterbox, b: letterbox } })
|
||||
|
||||
@@ -24,4 +24,30 @@ describe("send button", () => {
|
||||
fireEvent.click(await screen.findByRole("button", { name: "Enviar de novo a que já tinha ido" }));
|
||||
await waitFor(() => expect(calls).toEqual([[["a", "b"], false], [["a"], true]]));
|
||||
});
|
||||
|
||||
it("remembers the chosen destination across a remount (tab switch)", () => {
|
||||
try {
|
||||
window.localStorage.clear();
|
||||
} catch {
|
||||
/* jsdom without storage */
|
||||
}
|
||||
const api = {} as unknown as ApiClient;
|
||||
const targets = [
|
||||
{ id: "zz", name: "ZZ", kind: "ZEROZERO" },
|
||||
{ id: "fpa", name: "FPA", kind: "NEXTCLOUD" },
|
||||
] as unknown as DeliveryTarget[];
|
||||
const view = render(
|
||||
<MemoryRouter>
|
||||
<SendButton api={api} orgId="org" selection={[]} targets={targets} onQueued={() => {}} />
|
||||
</MemoryRouter>,
|
||||
);
|
||||
fireEvent.change(screen.getByRole("combobox"), { target: { value: "fpa" } });
|
||||
view.unmount();
|
||||
render(
|
||||
<MemoryRouter>
|
||||
<SendButton api={api} orgId="org" selection={[]} targets={targets} onQueued={() => {}} />
|
||||
</MemoryRouter>,
|
||||
);
|
||||
expect((screen.getByRole("combobox") as HTMLSelectElement).value).toBe("fpa");
|
||||
});
|
||||
});
|
||||
@@ -26,7 +26,10 @@ export function SendButton(props: { api: ApiClient; orgId: string; selection: Ph
|
||||
const [busy, setBusy] = useState(false);
|
||||
const [note, setNote] = useState<string | null>(null);
|
||||
useEffect(() => {
|
||||
if (targets.length && !targets.some((x) => x.id === targetId)) setTargetId(targets[0]!.id);
|
||||
if (targets.length && !targets.some((x) => x.id === targetId)) {
|
||||
setTargetId(targets[0]!.id);
|
||||
prefs.set(LAST_TARGET, targets[0]!.id);
|
||||
}
|
||||
}, [targets, targetId]);
|
||||
useEffect(() => setAlready([]), [targetId, eventId]);
|
||||
useEffect(() => {
|
||||
@@ -84,7 +87,7 @@ export function SendButton(props: { api: ApiClient; orgId: string; selection: Ph
|
||||
<span className="relative flex items-center gap-1">
|
||||
{target?.kind === "ZEROZERO" && eventId && <ZerozeroGamePicker api={api} orgId={orgId} targetId={targetId} eventId={eventId} compact />}
|
||||
{targets.length > 1 && (
|
||||
<select aria-label={t.deliverTo} value={targetId} onChange={(e) => setTargetId(e.target.value)} className="h-6 max-w-[140px] border border-black bg-cell px-1 text-[12px] text-ink">
|
||||
<select aria-label={t.deliverTo} value={targetId} onChange={(e) => { setTargetId(e.target.value); prefs.set(LAST_TARGET, e.target.value); }} className="h-6 max-w-[140px] border border-black bg-cell px-1 text-[12px] text-ink">
|
||||
{targets.map((x) => (
|
||||
<option key={x.id} value={x.id}>
|
||||
{x.name}
|
||||
|
||||
Reference in new issue
Block a user