diff --git a/src/pixelflow/api/static/index.html b/src/pixelflow/api/static/index.html index 996d4ae..6deff8f 100644 --- a/src/pixelflow/api/static/index.html +++ b/src/pixelflow/api/static/index.html @@ -1866,6 +1866,14 @@ Yerel Rötuş + + + + + + + Vesikalık + @@ -2051,6 +2059,28 @@ + + + + Baskı Kartı Düzeni + + 4'lü + 6'lı + 8'li + Tekli + + + + Kesim Kılavuz Çizgileri + + + + Ülke & Şablon Standartları + + + + + @@ -3599,6 +3629,52 @@ openExportOptimizerModal() }, { id: "loupe_inspector", group: "Görünüm & Renk", groupEn: "View & Color", name: "800% Piksel Büyüteci & Canlı Renk Pipeti", nameEn: "800% Pixel Loupe & Live Eyedropper", shortcut: "Z", action: () => toggleLoupe() }, { id: "exif_inspector", group: "Araçlar & Gizlilik", groupEn: "Tools & Privacy", name: "EXIF & Görsel Meta Verisi / Gizlilik Temizleyici", nameEn: "EXIF & Image Metadata Privacy Cleaner", shortcut: "Ctrl+I", action: () => openExifModal() }, + { id: "biometric_passport", group: "Belge & Evrak", groupEn: "Document & Office", name: "Biyometrik Vesikalık & 10x15cm Baskı Şablonu", nameEn: "Biometric Passport & 10x15cm Print Sheet", action: () => { switchLeftTab("biometric"); if (document.getElementById("proLeftPanel")?.classList.contains("collapsed")) toggleLeftPanel(); applyBiometricPreset("icao_35x45"); } }, + { id: "markup_revision", group: "Çizim & Revizyon", groupEn: "Markup & Revision", name: "Kırmızı Revizyon Damgası (REVİZYON 1)", nameEn: "Red Revision Stamp", action: () => addQuickMarkup("badge", "REVİZYON 1", [239, 68, 68]) }, + { id: "markup_approval", group: "Çizim & Revizyon", groupEn: "Markup & Revision", name: "Yeşil Onay Rozeti (ONAYLANDI)", nameEn: "Green Approved Stamp", action: () => addQuickMarkup("badge", "ONAYLANDI", [16, 185, 129]) }, + { id: "markup_arrow", group: "Çizim & Revizyon", groupEn: "Markup & Revision", name: "Dikkat & Açıklama Oku (Arrow)", nameEn: "Callout Arrow", action: () => addQuickMarkup("arrow", "", [239, 68, 68]) }, // Belge & Evrak { id: "deskew", group: "Belge & Evrak", groupEn: "Document & Office", name: "Akıllı Belge Köşesi & 4-Nokta Perspektif Düzelt", nameEn: "Auto Corner Detection & Perspective Deskew", action: () => quickAdd("perspective_warp") }, @@ -7616,8 +7698,148 @@ ' + }, + { + id: "us_visa", + preset: "us_visa_50x50", + name: "50x50mm ABD Vizesi (2x2\")", + nameEn: "50x50mm US Visa (2x2\")", + desc: "Green Card, DS-160 ve ABD vize başvuru standardı", + descEn: "Green Card, DS-160 & US Visa standard", + iconSvg: '' + }, + { + id: "standard_license", + preset: "standard_50x60", + name: "50x60mm Standart Vesikalık", + nameEn: "50x60mm Large Portrait", + desc: "Diplomalar, kurumsal kartlar ve resmi evraklar", + descEn: "Diplomas, corporate cards & official forms", + iconSvg: '' + } + ]; + + let currentBioPreset = "icao_35x45"; + let currentBioLayout = "4_up"; + let currentBioCutLines = true; + + function renderBiometricVitrin() { + const grid = document.getElementById("biometricVitrinGrid"); + if (!grid) return; + grid.innerHTML = PRO_BIOMETRIC_PRESETS.map(b => { + const title = currentLang === "en" ? b.nameEn : b.name; + const sub = currentLang === "en" ? b.descEn : b.desc; + const isSelected = (currentBioPreset === b.preset); + return ` + + + ${b.iconSvg} + + + ${title} + ${sub} + + + `; + }).join(""); + } + + function applyBiometricPreset(presetKey) { + currentBioPreset = presetKey; + let step = activeSteps.find(s => s.op === "biometric_sheet"); + const params = { + preset: presetKey, + layout: currentBioLayout, + dpi: 300, + sheet_width_mm: 150.0, + sheet_height_mm: 100.0, + draw_cut_lines: currentBioCutLines + }; + if (step) { + step.params = params; + selectedStepId = step.id; + } else { + const id = stepCounter++; + activeSteps.push({ + id, + op: "biometric_sheet", + name: `katman_${id}_biometric`, + params + }); + selectedStepId = id; + } + renderBiometricVitrin(); + pushHistory(); + renderStepsUI(); + scheduleRender(); + statusMessage.textContent = currentLang === "en" ? `✓ Biometric template applied (${presetKey})` : `✓ Biyometrik şablon uygulandı (${presetKey})`; + } + + function setBioLayout(layout) { + currentBioLayout = layout; + ["4", "6", "8", "1"].forEach(k => { + const keyMap = { "4": "4_up", "6": "6_up", "8": "8_up", "1": "single" }; + const b = document.getElementById("btnBioLayout" + k); + if (b) b.classList.toggle("active", keyMap[k] === layout); + }); + let step = activeSteps.find(s => s.op === "biometric_sheet"); + if (step) { + step.params.layout = layout; + pushHistory(); + renderStepsUI(); + scheduleRender(); + } else { + applyBiometricPreset(currentBioPreset); + } + } + + function toggleBioCutLines(checked) { + currentBioCutLines = checked; + let step = activeSteps.find(s => s.op === "biometric_sheet"); + if (step) { + step.params.draw_cut_lines = checked; + pushHistory(); + renderStepsUI(); + scheduleRender(); + } + } + + function addQuickMarkup(kind, text, color) { + const id = stepCounter++; + activeSteps.push({ + id, + op: "markup", + name: `katman_${id}_${kind}`, + params: { + kind, + text: text || "REVİZYON 1", + x1: 40, + y1: 40, + x2: 180, + y2: 180, + color: color || [239, 68, 68], + stroke_width: 3, + fill_opacity: kind === "box" ? 0.25 : 0.0 + } + }); + selectedStepId = id; + pushHistory(); + renderStepsUI(); + scheduleRender(); + statusMessage.textContent = currentLang === "en" ? `✓ Markup added: ${kind}` : `✓ Vektör işaretleme eklendi: ${kind}`; + } + function switchLeftTab(tabKey) { - const tabs = ["presets", "crop", "palette", "stamps", "artfx", "frames", "mask", "docs", "history"]; + const tabs = ["presets", "crop", "palette", "stamps", "artfx", "frames", "mask", "biometric", "docs", "history"]; tabs.forEach(t => { const btn = document.getElementById("segTab" + t.charAt(0).toUpperCase() + t.slice(1)); const content = document.getElementById("tabContent" + t.charAt(0).toUpperCase() + t.slice(1)); @@ -7633,6 +7855,7 @@ np.ndarray: + h, w = rgb.shape[:2] + target_ratio = target_w / target_h + current_ratio = w / h + if current_ratio > target_ratio: + new_w = round(h * target_ratio) + start_x = (w - new_w) // 2 + cropped = rgb[:, start_x : start_x + new_w] + else: + new_h = round(w / target_ratio) + start_y = (h - new_h) // 2 + cropped = rgb[start_y : start_y + new_h, :] + resized = cv2.resize(cropped, (target_w, target_h), interpolation=cv2.INTER_AREA) + return cast(np.ndarray, resized) + + +def _get_grid_dims(layout: BiometricLayout) -> tuple[int, int]: + if layout == "6_up": + return 2, 3 + if layout == "8_up": + return 2, 4 + return 2, 2 + + +def _tile_photos_on_sheet( + sheet: np.ndarray, + photo: np.ndarray, + layout: BiometricLayout, + draw_cut_lines: bool, +) -> np.ndarray: + rows, cols = _get_grid_dims(layout) + sh_h, sh_w = sheet.shape[:2] + ph_h, ph_w = photo.shape[:2] + gap_x = max(10, (sh_w - cols * ph_w) // (cols + 1)) + gap_y = max(10, (sh_h - rows * ph_h) // (rows + 1)) + for r in range(rows): + for c in range(cols): + x = gap_x + c * (ph_w + gap_x) + y = gap_y + r * (ph_h + gap_y) + sheet[y : y + ph_h, x : x + ph_w] = photo + if draw_cut_lines: + cv2.rectangle(sheet, (x - 1, y - 1), (x + ph_w, y + ph_h), (210, 210, 210), 1) + return sheet + + +@register_operation("biometric_sheet") +class BiometricSheetOperation(ImageOperation[BiometricSheetParams]): + operation_name = "biometric_sheet" + params_model = BiometricSheetParams + + def _execute(self, image: ImageArray) -> ImageArray: + u8 = to_uint8(image) + rgb = ensure_rgb(u8) + mm_to_px = self.params.dpi / 25.4 + pw_mm, ph_mm = PRESET_DIMENSIONS_MM[self.params.preset] + target_pw = max(10, round(pw_mm * mm_to_px)) + target_ph = max(10, round(ph_mm * mm_to_px)) + photo = _crop_and_scale_photo(rgb, target_pw, target_ph) + if self.params.layout == "single": + return cast(ImageArray, photo) + rows, cols = _get_grid_dims(self.params.layout) + min_w = cols * target_pw + (cols + 1) * 10 + min_h = rows * target_ph + (rows + 1) * 10 + sheet_w = max(min_w, round(self.params.sheet_width_mm * mm_to_px)) + sheet_h = max(min_h, round(self.params.sheet_height_mm * mm_to_px)) + sheet = np.full((sheet_h, sheet_w, 3), self.params.background_color, dtype=np.uint8) + result = _tile_photos_on_sheet( + sheet, photo, self.params.layout, self.params.draw_cut_lines + ) + return cast(ImageArray, result) diff --git a/src/pixelflow/operations/markup.py b/src/pixelflow/operations/markup.py new file mode 100644 index 0000000..5ea1fee --- /dev/null +++ b/src/pixelflow/operations/markup.py @@ -0,0 +1,98 @@ +from __future__ import annotations + +from typing import Literal + +import cv2 +import numpy as np +from pydantic import Field + +from pixelflow.core.image_utils import ensure_rgb, merge_alpha, split_alpha, to_uint8 +from pixelflow.core.operation import ImageArray, ImageOperation, OperationParams +from pixelflow.core.registry import register_operation + +MarkupKind = Literal["badge", "arrow", "box"] + + +class MarkupParams(OperationParams): + kind: MarkupKind = "badge" + x1: int = 50 + y1: int = 50 + x2: int = 150 + y2: int = 150 + color: tuple[int, int, int] = (239, 68, 68) + stroke_width: int = Field(default=3, ge=1, le=20) + text: str = "REVİZYON 1" + fill_opacity: float = Field(default=0.0, ge=0.0, le=1.0) + + +def _draw_markup_badge( + canvas: np.ndarray, + params: MarkupParams, +) -> None: + font = cv2.FONT_HERSHEY_SIMPLEX + scale = 0.55 + thick = max(1, params.stroke_width // 2) + (tw, th), _ = cv2.getTextSize(params.text, font, scale, thick) + pad = 8 + bx1 = params.x1 + by1 = params.y1 + bx2 = bx1 + tw + pad * 2 + by2 = by1 + th + pad * 2 + cv2.rectangle(canvas, (bx1, by1), (bx2, by2), params.color, -1) + tx = bx1 + pad + ty = by1 + th + pad + cv2.putText(canvas, params.text, (tx, ty), font, scale, (255, 255, 255), thick, cv2.LINE_AA) + + +def _draw_markup_arrow( + canvas: np.ndarray, + params: MarkupParams, +) -> None: + pt1 = (params.x1, params.y1) + pt2 = (params.x2, params.y2) + cv2.arrowedLine( + canvas, + pt1, + pt2, + params.color, + params.stroke_width, + tipLength=0.2, + line_type=cv2.LINE_AA, + ) + + +def _draw_markup_box( + canvas: np.ndarray, + params: MarkupParams, +) -> None: + pt1 = (min(params.x1, params.x2), min(params.y1, params.y2)) + pt2 = (max(params.x1, params.x2), max(params.y1, params.y2)) + if params.fill_opacity > 0.0: + overlay = canvas.copy() + cv2.rectangle(overlay, pt1, pt2, params.color, -1) + blended = cv2.addWeighted( + overlay, params.fill_opacity, canvas, 1.0 - params.fill_opacity, 0.0 + ) + canvas[:, :] = blended[:, :] + cv2.rectangle(canvas, pt1, pt2, params.color, params.stroke_width, lineType=cv2.LINE_AA) + + +@register_operation("markup") +class MarkupOperation(ImageOperation[MarkupParams]): + operation_name = "markup" + params_model = MarkupParams + + def _execute(self, image: ImageArray) -> ImageArray: + u8 = to_uint8(image) + base, alpha = split_alpha(u8) + rgb = ensure_rgb(base) + canvas = rgb.copy() + if self.params.kind == "badge": + _draw_markup_badge(canvas, self.params) + elif self.params.kind == "arrow": + _draw_markup_arrow(canvas, self.params) + else: + _draw_markup_box(canvas, self.params) + if alpha is not None: + return merge_alpha(canvas, alpha) + return canvas diff --git a/tests/test_biometric.py b/tests/test_biometric.py new file mode 100644 index 0000000..2288f18 --- /dev/null +++ b/tests/test_biometric.py @@ -0,0 +1,49 @@ +from __future__ import annotations + +import numpy as np + +from pixelflow.core.registry import default_registry +from pixelflow.operations.biometric import ( + BiometricSheetOperation, + BiometricSheetParams, +) + + +def test_biometric_single_photo_crop() -> None: + img = np.full((200, 100, 3), 180, dtype=np.uint8) + params = BiometricSheetParams(preset="icao_35x45", layout="single", dpi=100) + op = BiometricSheetOperation(params) + res = op.apply(img) + h, w = res.shape[:2] + assert abs((w / h) - (35 / 45)) < 0.05 + + +def test_biometric_4_up_sheet_dimensions() -> None: + img = np.full((120, 120, 3), 150, dtype=np.uint8) + params = BiometricSheetParams(preset="icao_35x45", layout="4_up", dpi=100) + op = BiometricSheetOperation(params) + res = op.apply(img) + assert res.shape == (394, 591, 3) + + +def test_biometric_us_visa_preset() -> None: + img = np.full((100, 100, 3), 120, dtype=np.uint8) + params = BiometricSheetParams(preset="us_visa_50x50", layout="6_up", dpi=72) + op = BiometricSheetOperation(params) + res = op.apply(img) + assert res.ndim == 3 + assert res.shape[2] == 3 + + +def test_biometric_8_up_layout() -> None: + img = np.full((100, 100, 3), 200, dtype=np.uint8) + params = BiometricSheetParams(preset="standard_50x60", layout="8_up", dpi=72) + op = BiometricSheetOperation(params) + res = op.apply(img) + assert res.shape[0] > 0 + assert res.shape[1] > 0 + + +def test_biometric_registered() -> None: + op_cls = default_registry.get("biometric_sheet") + assert op_cls is BiometricSheetOperation diff --git a/tests/test_markup.py b/tests/test_markup.py new file mode 100644 index 0000000..1ea09db --- /dev/null +++ b/tests/test_markup.py @@ -0,0 +1,56 @@ +from __future__ import annotations + +import numpy as np + +from pixelflow.core.registry import default_registry +from pixelflow.operations.markup import ( + MarkupOperation, + MarkupParams, +) + + +def test_markup_badge_render() -> None: + img = np.zeros((100, 200, 3), dtype=np.uint8) + params = MarkupParams(kind="badge", x1=10, y1=10, text="REVISION", color=(255, 0, 0)) + op = MarkupOperation(params) + res = op.apply(img) + assert np.any(res > 0) + + +def test_markup_arrow_render() -> None: + img = np.zeros((100, 100, 3), dtype=np.uint8) + params = MarkupParams(kind="arrow", x1=10, y1=10, x2=80, y2=80, color=(0, 255, 0)) + op = MarkupOperation(params) + res = op.apply(img) + assert np.any(res[:, :, 1] == 255) + + +def test_markup_box_with_fill() -> None: + img = np.zeros((100, 100, 3), dtype=np.uint8) + params = MarkupParams( + kind="box", + x1=20, + y1=20, + x2=80, + y2=80, + color=(0, 0, 255), + fill_opacity=0.5, + ) + op = MarkupOperation(params) + res = op.apply(img) + assert res[50, 50, 2] > 50 + + +def test_markup_alpha_preservation() -> None: + rgba = np.full((50, 50, 4), 100, dtype=np.uint8) + rgba[:, :, 3] = 200 + params = MarkupParams(kind="arrow", x1=5, y1=5, x2=40, y2=40) + op = MarkupOperation(params) + res = op.apply(rgba) + assert res.shape == (50, 50, 4) + assert np.all(res[:, :, 3] == 200) + + +def test_markup_registered() -> None: + op_cls = default_registry.get("markup") + assert op_cls is MarkupOperation