diff --git a/README.md b/README.md index 7f67b0e..df45c1b 100644 --- a/README.md +++ b/README.md @@ -56,7 +56,7 @@ Or skip the install entirely and load it from a CDN — this is what the [live demo](https://h4md1.fr/visual-image-tool/) does: ```html - + ``` Pin the exact version rather than the major in production. There is a runnable diff --git a/demo/index.html b/demo/index.html index 0d85362..ab738b3 100644 --- a/demo/index.html +++ b/demo/index.html @@ -66,351 +66,719 @@ rel="stylesheet" href="https://cdn.jsdelivr.net/npm/prismjs@1.29.0/themes/prism.min.css" /> + + -
- VisualImageTool logo -

VisualImageTool

-

- Let people pick the focal point and crop zone. You get the pixel - coordinates. -

-
-
-

Interactive demo

-
-
- Demo landscape + + +
+
+
+ + Visual Image Tool
-
-

Controls

- - -

Current data

-
No data available
-

Actions

- - + +

+ Let someone say where the subject is. Get back numbers. +

+ +

+ A zero-dependency vanilla JS tool to pick focal points and crop zones + on images. It hands you pixel coordinates you can feed straight into + your image pipeline — it never touches the pixels itself. +

+ +
    +
  • 3.6 kB gzipped
  • +
  • Zero dependencies
  • +
  • TypeScript declarations included
  • +
  • MIT
  • +
+ +
+
+ npm install @h4md1/visual-image-tool + +
+ Try it below + GitHub
- - - - - - Try online on JSFiddle - -
Usage without installation
-

- You can use VisualImageTool directly in your HTML pages without - installing any dependency, thanks to the CDN - jsdelivr: -

-
<!-- UMD via CDN -->
-<script src="https://cdn.jsdelivr.net/npm/@h4md1/visual-image-tool/dist/visual-image-tool.umd.js"></script>
-
-<!-- OR ESM via CDN -->
-<script type="module">
-  import { VisualImageTool } from 'https://cdn.jsdelivr.net/npm/@h4md1/visual-image-tool/dist/visual-image-tool.esm.js';
-  // Your code here
-</script>
- -
Quick demos
- +
-
Features
-
    -
  • - Focus point: Set a point of interest on the image - with a visual marker -
  • -
  • - Crop zone: Define a crop zone with resize handles -
  • -
  • - No dependencies: Works without external libraries -
  • -
  • Simple API: Clear and easy-to-use interface
  • -
  • Customizable: Flexible configuration options
  • -
  • Responsive: Adapts to screen resizing
  • -
- -
Installation
-
npm install @h4md1/visual-image-tool
- -
Quick start guide
-
    -
  1. - Import -
    // ES modules (recommended)
    -import { VisualImageTool } from '@h4md1/visual-image-tool';
    -
    -// CommonJS
    -const { VisualImageTool } = require('@h4md1/visual-image-tool');
    -
    -// UMD (script tag)
    -<script src="node_modules/@h4md1/visual-image-tool/dist/visual-image-tool.umd.js"></script>
    -
    -
  2. -
  3. - Initialization -
    // With an import or require you hold the class itself.
    -// Loaded from the UMD script tag it is VisualImageTool.VisualImageTool.
    -const imageTool = new VisualImageTool({
    -  imageElement: document.getElementById('myImage'),
    -  debug: true, // Enable debug logs for overlay positioning (optional)
    +    
    +
    +

    Drag the marker. Resize the box. Watch the numbers.

    +

    + This is the actual library running on this page, loaded from a CDN + with no build step. It starts by demonstrating itself — then it's + yours. +

    + +
    +
    + A landscape photograph used to demonstrate the focal point and crop zone tools +
    +
    +

    Controls

    + + +

    Current data

    +
    No data available
    +

    Actions

    + + +
    +
    +
    + +
    +

    What you get back, and where it goes

    +

    + Coordinates come back in the image's original pixels, + so they stay valid at any display size. +

    +
    + + + + + + + + + + + + + + + + + +
    What you getWhere it tends to go
    focusPoint: {x, y} + CSS object-position, imgix + fp-x/fp-y, Cloudinary gravity +
    cropZone: {x, y, w, h} + a server-side crop with sharp or ImageMagick, or a stored crop + rectangle +
    +
    +
    + +
    +

    Is this the right tool?

    +
    +
    +

    Yes, if

    +

    + you need a person to mark where the subject of an image + is, and you want those positions back as numbers — to store on a + record, or hand to an image pipeline. +

    +
    +
    +

    No, if

    +

    + you need the browser to actually produce the cropped image — + rotation, zoom, canvas export, file output. This library never + touches pixels. A full cropper such as + Cropper.js is built for that job. +

    +
    +
    +
    + +
    +

    Install

    +
    npm install @h4md1/visual-image-tool
    +

    + Or skip the install entirely and load it from a CDN — this is what the + demo above does. Pin the exact version in production. +

    +
    <script src="https://cdn.jsdelivr.net/npm/@h4md1/visual-image-tool@0.3.0/dist/visual-image-tool.umd.js"></script>
    +

    + There is a runnable + JSFiddle + if you would rather poke at it first. +

    +
    + +
    +

    Quick start

    +
    import { VisualImageTool } from "@h4md1/visual-image-tool";
    +
    +const tool = new VisualImageTool({
    +  imageElement: document.getElementById("myImage"),
       onChange: (data) => {
    -    console.log('Focus point:', data.focusPoint);
    -    console.log('Crop zone:', data.cropZone);
    -  }
    -});
    -
  4. -
  5. - Using the features -
    // Enable the focus point
    -imageTool.toggleFocusPoint(true);
    -
    -// Enable the crop zone
    -imageTool.toggleCropZone(true);
    -
    -// Manually set a focus point
    -imageTool.setFocusPoint(x, y);
    -
    -// Manually set a crop zone
    -imageTool.setCropZone(x, y, width, height);
    -
    -// Get current values
    -const focusPoint = imageTool.getFocusPoint();
    -const cropZone = imageTool.getCropZone();
    -
    -
  6. -
- -
Full API
-

- The complete reference — every method, all configuration options and the - framework integration examples — lives in the - README. It is kept in one place so this page cannot drift out of step with - the code. -

- -
Browser Compatibility
-
    -
  • Chrome (latest versions)
  • -
  • Firefox (latest versions)
  • -
  • Safari (latest versions)
  • -
  • Edge (latest versions)
  • -
- -
License
-

MIT

+ console.log(data.focusPoint); // { x, y } in original pixels + console.log(data.cropZone); // { x, y, width, height } + }, +}); + +tool.toggleFocusPoint(true); +tool.toggleCropZone(true);
+

+ Loading the UMD build from a script tag? The global + holds the named export, so the class is + VisualImageTool.VisualImageTool. With an + import or require you already have the class + itself. +

+ + +
+

It's plain DOM, so it drops into anything

+ +
+ +
+

The whole API

+
+ + + + + + + + + + + + + + + + + + + + + + + + + + + +
toggleFocusPoint(active?)Show or hide the focus point marker.
toggleCropZone(active?)Show or hide the crop zone.
setFocusPoint(x, y)Place the marker, in original pixels.
setCropZone(x, y, w, h)Place and size the crop zone.
+ getFocusPoint() / getCropZone() + Read the current values.
getImageDimensions()The image's natural size.
+
+

+ Setters return the instance, so they chain. Full options and types are + in the + README. +

+
+ +
+

Browser support

+

Current versions of Chrome, Firefox, Safari and Edge.

+
- + + + - + +