senangwebs-photobooth 1.0.1 → 1.0.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +72 -72
- package/dist/swp.css +261 -255
- package/dist/swp.js +1 -1
- package/package.json +4 -1
- package/src/css/swp.css +261 -255
- package/src/js/swp.js +713 -611
- package/swp_preview.png +0 -0
- package/spec.md +0 -239
package/swp_preview.png
CHANGED
|
Binary file
|
package/spec.md
DELETED
|
@@ -1,239 +0,0 @@
|
|
|
1
|
-
# SenangWebs Photobooth (SWP) - Specification
|
|
2
|
-
|
|
3
|
-
## 1. Introduction
|
|
4
|
-
|
|
5
|
-
SenangWebs Photobooth (SWP) is a lightweight and easy-to-use JavaScript library for client-side photo editing. It provides a simple and intuitive interface for users to perform basic image manipulations directly in the browser. This document outlines the technical specifications, features, and API of the SWP library.
|
|
6
|
-
|
|
7
|
-
The primary goal of SWP is to offer a straightforward solution for developers to integrate photo editing capabilities into their web applications without the need for complex server-side processing.
|
|
8
|
-
|
|
9
|
-
## 2. Features
|
|
10
|
-
|
|
11
|
-
SWP will provide the following core photo editing features:
|
|
12
|
-
|
|
13
|
-
### 2.1. Core Manipulations
|
|
14
|
-
|
|
15
|
-
* **Cropping:** Users can select an area of the image and crop it to the desired dimensions. This includes options for predefined aspect ratios (e.g., 1:1, 4:3, 16:9) and a freeform selection.
|
|
16
|
-
* **Rotating:** Users can rotate the image in 90-degree increments to the left and right.
|
|
17
|
-
* **Flipping:** Users can flip the image horizontally and vertically.
|
|
18
|
-
|
|
19
|
-
### 2.2. Adjustments
|
|
20
|
-
|
|
21
|
-
Users can fine-tune the appearance of the image with the following adjustments:
|
|
22
|
-
|
|
23
|
-
* **Brightness:** Increase or decrease the overall lightness of the image.
|
|
24
|
-
* **Contrast:** Adjust the difference between the light and dark areas of the image.
|
|
25
|
-
* **Saturation:** Control the intensity of the colors in the image.
|
|
26
|
-
|
|
27
|
-
### 2.3. Filters
|
|
28
|
-
|
|
29
|
-
A selection of pre-defined filters will be available to apply one-click effects to the image. These filters will be implemented using CSS `filter` properties. Initial filters will include:
|
|
30
|
-
|
|
31
|
-
* **Grayscale:** Converts the image to shades of gray.
|
|
32
|
-
* **Sepia:** Gives the image a reddish-brown tone.
|
|
33
|
-
* **Invert:** Inverts the colors of the image.
|
|
34
|
-
* **Blur:** Applies a Gaussian blur to the image.
|
|
35
|
-
|
|
36
|
-
## 3. Technical Specifications
|
|
37
|
-
|
|
38
|
-
### 3.1. Architecture
|
|
39
|
-
|
|
40
|
-
SWP is a client-side JavaScript library with no server-side dependencies. It will utilize the HTML5 Canvas API for image rendering and manipulation. This approach ensures that all image processing is done within the user's browser, providing a fast and responsive experience.
|
|
41
|
-
|
|
42
|
-
### 3.2. Dependencies
|
|
43
|
-
|
|
44
|
-
The library will have no external dependencies to keep it lightweight and easy to integrate.
|
|
45
|
-
|
|
46
|
-
### 3.3. Browser Compatibility
|
|
47
|
-
|
|
48
|
-
SWP will be compatible with all modern web browsers that support the HTML5 Canvas API and the CSS `filter` property. The target browsers include:
|
|
49
|
-
|
|
50
|
-
* Google Chrome (latest 2 versions)
|
|
51
|
-
* Mozilla Firefox (latest 2 versions)
|
|
52
|
-
* Microsoft Edge (latest 2 versions)
|
|
53
|
-
* Safari (latest 2 versions)
|
|
54
|
-
|
|
55
|
-
### 3.4. File Output
|
|
56
|
-
|
|
57
|
-
The edited image can be exported in the following formats:
|
|
58
|
-
|
|
59
|
-
* JPEG
|
|
60
|
-
* PNG
|
|
61
|
-
|
|
62
|
-
Users will be able to specify the output format and, for JPEG, the image quality.
|
|
63
|
-
|
|
64
|
-
## 4. API Reference
|
|
65
|
-
|
|
66
|
-
The SWP library will be instantiated on a container `div` element in the HTML.
|
|
67
|
-
|
|
68
|
-
### 4.1. Initialization
|
|
69
|
-
|
|
70
|
-
To initialize the photo booth, create a new instance of `SenangWebsPhotobooth`:
|
|
71
|
-
|
|
72
|
-
```javascript
|
|
73
|
-
const swp = new SWP(container, options);
|
|
74
|
-
```
|
|
75
|
-
|
|
76
|
-
**Parameters:**
|
|
77
|
-
|
|
78
|
-
* `container` (HTMLElement): The DOM element that will contain the photo booth interface.
|
|
79
|
-
* `options` (Object): An optional configuration object.
|
|
80
|
-
|
|
81
|
-
**Options:**
|
|
82
|
-
|
|
83
|
-
* `imageUrl` (String): The URL of the image to be loaded into the editor.
|
|
84
|
-
* `width` (Number): The width of the editor in pixels.
|
|
85
|
-
* `height` (Number): The height of the editor in pixels.
|
|
86
|
-
|
|
87
|
-
### 4.2. Methods
|
|
88
|
-
|
|
89
|
-
The `swp` instance will expose the following public methods:
|
|
90
|
-
|
|
91
|
-
#### `loadImage(imageUrl)`
|
|
92
|
-
|
|
93
|
-
Loads a new image into the editor.
|
|
94
|
-
|
|
95
|
-
* **`imageUrl`** (String): The URL of the image to load.
|
|
96
|
-
|
|
97
|
-
#### `crop(x, y, width, height)`
|
|
98
|
-
|
|
99
|
-
Crops the image to the specified dimensions.
|
|
100
|
-
|
|
101
|
-
* **`x`** (Number): The x-coordinate of the top-left corner of the crop area.
|
|
102
|
-
* **`y`** (Number): The y-coordinate of the top-left corner of the crop area.
|
|
103
|
-
* **`width`** (Number): The width of the crop area.
|
|
104
|
-
* **`height`** (Number): The height of the crop area.
|
|
105
|
-
|
|
106
|
-
#### `rotate(degrees)`
|
|
107
|
-
|
|
108
|
-
Rotates the image by the specified degrees.
|
|
109
|
-
|
|
110
|
-
* **`degrees`** (Number): The degree of rotation. Positive values rotate clockwise, negative values rotate counter-clockwise. For the initial version, this will be limited to multiples of 90.
|
|
111
|
-
|
|
112
|
-
#### `flip(direction)`
|
|
113
|
-
|
|
114
|
-
Flips the image.
|
|
115
|
-
|
|
116
|
-
* **`direction`** (String): The direction to flip. Can be `'horizontal'` or `'vertical'`.
|
|
117
|
-
|
|
118
|
-
#### `setAdjustment(adjustment, value)`
|
|
119
|
-
|
|
120
|
-
Applies an adjustment to the image.
|
|
121
|
-
|
|
122
|
-
* **`adjustment`** (String): The adjustment to apply. Can be `'brightness'`, `'contrast'`, or `'saturation'`.
|
|
123
|
-
* **`value`** (Number): The value of the adjustment. The range will be specific to each adjustment.
|
|
124
|
-
|
|
125
|
-
#### `applyFilter(filterName)`
|
|
126
|
-
|
|
127
|
-
Applies a pre-defined filter to the image.
|
|
128
|
-
|
|
129
|
-
* **`filterName`** (String): The name of the filter to apply (e.g., `'grayscale'`, `'sepia'`).
|
|
130
|
-
|
|
131
|
-
#### `reset()`
|
|
132
|
-
|
|
133
|
-
Resets all edits and reverts the image to its original state.
|
|
134
|
-
|
|
135
|
-
#### `getImageData(format, quality)`
|
|
136
|
-
|
|
137
|
-
Exports the edited image data.
|
|
138
|
-
|
|
139
|
-
* **`format`** (String): The desired output format (`'jpeg'` or `'png'`). Defaults to `'jpeg'`.
|
|
140
|
-
* **`quality`** (Number): For JPEG format, a number between 0 and 1 representing the image quality. Defaults to 0.9.
|
|
141
|
-
* **Returns:** A data URL representing the image.
|
|
142
|
-
|
|
143
|
-
### 4.3. Events
|
|
144
|
-
|
|
145
|
-
The SWP instance will emit the following events that can be listened to:
|
|
146
|
-
|
|
147
|
-
* **`'load'`**: Fired when an image has been successfully loaded into the editor.
|
|
148
|
-
* **`'change'`**: Fired whenever an edit is applied to the image.
|
|
149
|
-
* **`'save'`**: Fired when the image data has been successfully exported.
|
|
150
|
-
|
|
151
|
-
## 5. User Interface
|
|
152
|
-
|
|
153
|
-
The SWP library will generate a user-friendly interface within the specified container element. The UI will consist of:
|
|
154
|
-
|
|
155
|
-
* **Canvas Area:** The main area where the image is displayed and manipulated.
|
|
156
|
-
* **Toolbar:** A toolbar containing buttons for all the editing features (crop, rotate, flip, adjustments, filters).
|
|
157
|
-
* **Adjustment Sliders:** For adjustments like brightness and contrast, sliders will be provided for intuitive control.
|
|
158
|
-
* **Filter Thumbnails:** A gallery of thumbnails will display a preview of each filter effect.
|
|
159
|
-
|
|
160
|
-
## 6. Example Usage
|
|
161
|
-
|
|
162
|
-
### HTML/Declarative Approach
|
|
163
|
-
|
|
164
|
-
```html
|
|
165
|
-
<!DOCTYPE html>
|
|
166
|
-
<html>
|
|
167
|
-
<head>
|
|
168
|
-
<title>SenangWebs Photobooth</title>
|
|
169
|
-
<link rel="stylesheet" href="swp.css">
|
|
170
|
-
</head>
|
|
171
|
-
<body>
|
|
172
|
-
<!-- Basic initialization -->
|
|
173
|
-
<div data-swp></div>
|
|
174
|
-
|
|
175
|
-
<!-- With configuration -->
|
|
176
|
-
<div data-swp
|
|
177
|
-
data-swp-width="900"
|
|
178
|
-
data-swp-height="600"
|
|
179
|
-
data-swp-show-labels="false"></div>
|
|
180
|
-
|
|
181
|
-
<!-- With custom labels -->
|
|
182
|
-
<div data-swp
|
|
183
|
-
data-swp-labels="upload: 'Muat Naik'; resize: 'Tukar Saiz'; save: 'Simpan'"></div>
|
|
184
|
-
|
|
185
|
-
<script src="swp.js"></script>
|
|
186
|
-
</body>
|
|
187
|
-
</html>
|
|
188
|
-
```
|
|
189
|
-
|
|
190
|
-
**Supported Data Attributes:**
|
|
191
|
-
- `data-swp` - Enables auto-initialization
|
|
192
|
-
- `data-swp-width` - Canvas width in pixels
|
|
193
|
-
- `data-swp-height` - Canvas height in pixels
|
|
194
|
-
- `data-swp-image-url` - URL of image to load on initialization
|
|
195
|
-
- `data-swp-show-icons` - Show/hide toolbar icons ("true" or "false")
|
|
196
|
-
- `data-swp-show-labels` - Show/hide toolbar labels ("true" or "false")
|
|
197
|
-
- `data-swp-labels` - Custom button labels in simple format (`key: 'value'; key2: 'value2'`) or JSON format
|
|
198
|
-
|
|
199
|
-
### JS/Programmatic Approach
|
|
200
|
-
|
|
201
|
-
```html
|
|
202
|
-
<!DOCTYPE html>
|
|
203
|
-
<html>
|
|
204
|
-
<head>
|
|
205
|
-
<title>SenangWebs Photobooth</title>
|
|
206
|
-
<link rel="stylesheet" href="senangwebs-photobooth.css">
|
|
207
|
-
</head>
|
|
208
|
-
<body>
|
|
209
|
-
<div id="photobooth-container"></div>
|
|
210
|
-
|
|
211
|
-
<script src="swp.js"></script>
|
|
212
|
-
<script>
|
|
213
|
-
const container = document.getElementById('photobooth-container');
|
|
214
|
-
const options = {
|
|
215
|
-
imageUrl: 'path/to/your/image.jpg',
|
|
216
|
-
width: 800,
|
|
217
|
-
height: 600
|
|
218
|
-
};
|
|
219
|
-
|
|
220
|
-
const swp = new SWP(container, options);
|
|
221
|
-
|
|
222
|
-
swp.on('change', () => {
|
|
223
|
-
console.log('Image has been edited.');
|
|
224
|
-
});
|
|
225
|
-
|
|
226
|
-
// Example of programmatically applying an edit
|
|
227
|
-
// swp.rotate(90);
|
|
228
|
-
</script>
|
|
229
|
-
</body>
|
|
230
|
-
</html>
|
|
231
|
-
```
|
|
232
|
-
|
|
233
|
-
## 7. Future Enhancements
|
|
234
|
-
|
|
235
|
-
* **More Filters and Adjustments:** Addition of more advanced filters and adjustments like temperature, tint, and vibrance.
|
|
236
|
-
* **Text and Stickers:** Ability to add text overlays and stickers to the image.
|
|
237
|
-
* **Redo/Undo Functionality:** A history mechanism to allow users to undo and redo their edits.
|
|
238
|
-
* **Touch Support:** Improved support for touch gestures on mobile devices.
|
|
239
|
-
* **Framework Integration:** Wrappers for popular JavaScript frameworks like React, Vue, and Angular.
|