write an html code to let the user import an image (packaging design of a box with 6 faces)
the user will select the 6 faces (rectangles) manually from the design image that just imported
the UI:
A canvas to show and handle the image that take the full page size
A button to import an image
Use middle mouse button for dragging. Use the mouse wheel to zoom in/out, focusing on the cursor position
let the user select multiple parts from the image (show the selection as rectangles)
make the selection rectangle stick in the image (zoom and move with the image).
label the rectangles by showing face_name on the centre of each rectangle.
The selections will stick to the image when zooming or moving.
a list of elements:
--- every element contain aliened sub-elements like so [{mark_thet_this_face_is_added} : {face_name} : [botton_add_face] [button_delet_face] [button_edit_face(this botton show the handels for modification)]]
--- the 6 faces is front, back, right, left, top and bottom.
--- this list let the user add and delete or edit (move or resize) the selection rectangles.
after clicking on edit face button show/hide 4 handles in the corners of the rectangle an 4 in the edge of the rectangle that was created for selection to let the user modify the size and emplacements the selection rectangle.
Assistant
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.
Certainly! Below is an HTML code that implements the functionality you've described. The code includes an image import button, a canvas for displaying and interacting with the image, zooming and panning functionality, selection of rectangles for each face, and a list of faces with controls to add, delete, or edit selections.
A toolbar at the top with the "Import Image" button and the list of faces with their controls.
A canvas inside a container that takes up the remaining space of the page. The canvas will display the image and handle user interactions.
CSS Styles:
Styles to ensure the canvas fills the available space and the toolbar and face list are properly aligned.
Styles for the selection handles and labels to make them visible and interactive.
JavaScript Functionality:
Image Importing:
When the user clicks "Import Image," it triggers a hidden file input to select an image.
The selected image is loaded and displayed on the canvas.
Zooming and Panning:
The user can zoom in and out using the mouse wheel. The zoom focuses on the cursor position.
Panning is done using the middle mouse button (button 1). Pressing it allows dragging the image around.
Selection of Faces:
Each face in the list (front, back, right, left, top, bottom) has associated buttons:
Add: Allows the user to start drawing a selection rectangle for that face.
Delete: Removes the selection rectangle for that face.
Edit: Toggles edit mode, enabling handles for resizing and moving the selection.
When adding a face, the user clicks and drags on the canvas to draw a rectangle. The rectangle sticks to the image and scales/moves with it.
The selection rectangles are stored in the selections object, keyed by face name.
Editing Selections:
In edit mode, handles appear at the corners of the selection rectangle.
The user can drag these handles to resize the rectangle.
If the user clicks inside the rectangle but not on a handle, they can move the entire rectangle.
Drawing Function (draw):
Clears the canvas and redraws the image and all selection rectangles.
Selection rectangles are drawn with red borders and have labels at their centers.
Event Handlers:
Notes:
The code uses plain JavaScript and canvas APIs to handle all interactions.
The selection rectangles are implemented in such a way that they stick to the image when zooming and panning.
The handles for editing are only visible when the user is in edit mode for a particular face.
The code assumes that the middle mouse button is used for panning, which may not be available on all devices (e.g., certain touchpads). You may want to adapt the code to support other input methods if necessary.
Usage:
Import an Image:
Click the "Import Image" button and select your packaging design image.
Select a Face to Add:
In the face list, click the "Add" button next to the face you want to define.
Click and drag on the canvas to draw a rectangle over the desired area.
Edit a Face:
Click the "Edit" button next to the face.
Drag the handles that appear around the rectangle to resize it.
Click inside the rectangle to move it.
Click "Done" to exit edit mode.
Delete a Face:
Click the "Delete" button next to the face to remove its selection rectangle.
Please Note:
This is a basic implementation and may need further enhancements for production use.
Error handling, such as checking for invalid operations or providing user feedback, can be added as needed.
Depending on browser security settings, the image may not load if running the HTML file directly from the local file system. Consider hosting it on a local server if you encounter issues.