word/edit: read fractional crop coordinates
authorMischa POSLAWSKY <perl@shiar.org>
Sun, 23 Jan 2022 00:51:12 +0000 (01:51 +0100)
committerMischa POSLAWSKY <perl@shiar.org>
Mon, 7 Feb 2022 17:42:33 +0000 (18:42 +0100)
Clean up various separators (,-x;:/) from manual input into common comma,
and allow dot for possible future fractions in large numbers:

UPDATE word SET image = jsonb_set(image, '{crop32}',
regexp_replace(image->>'crop32', '[^0-9,]', ',', 'g')
) WHERE image->>'crop32' IS NOT NULL;

Decided against dividing by 1000 to simplify code, but this would do that:

UPDATE word SET image = jsonb_set(image, '{crop32}',
to_jsonb(array_to_string(array(
SELECT unnest(string_to_array(image->>'crop32', ','))::float / 1000
), ','))
) WHERE image->>'crop32' IS NOT NULL;

word/editor.js

index 461bab0aa15a2b13ec83d57c7f58c8a43bedb4a7..4eb2382434c238792e0cc718c926737f757dcaf7 100644 (file)
@@ -126,7 +126,7 @@ document.addEventListener('DOMContentLoaded', () => {
                        const canvas = [thumbpreview.clientWidth, thumbpreview.clientHeight];
                        const border = [canvas[0], canvas[0] * imgpreview.height / imgpreview.width];
                        const minscale = Math.max(1, canvas[1] / border[1]); // 100% or fit width
-                       let crop = cropinput.value.split(/[^0-9]/).map(pos => pos / 1000);
+                       let crop = cropinput.value.split(/[^0-9.]/).map(pos => pos / 1000);
                        let scale = 1 / (crop[2] - crop[0]) || minscale;
                        crop.push(0); // defined y dimension
                        crop.splice(2); // end coordinates applied to zoom