106 lines
2 KiB
Markdown
106 lines
2 KiB
Markdown
|
# Image Speech Bubble Transformer
|
||
|
|
||
|
A TypeScript library for applying speech bubble effects to images with various transformation options.
|
||
|
|
||
|
## Installation
|
||
|
|
||
|
```bash
|
||
|
npm install image-speech-bubble-transformer
|
||
|
```
|
||
|
|
||
|
## Usage
|
||
|
|
||
|
```typescript
|
||
|
import {
|
||
|
createSpeechBubbleTransformer,
|
||
|
Orientation,
|
||
|
} from "image-speech-bubble-transformer";
|
||
|
import fs from "fs/promises";
|
||
|
|
||
|
async function example() {
|
||
|
// Create transformer instance
|
||
|
const transformer = createSpeechBubbleTransformer();
|
||
|
|
||
|
// Read image buffer
|
||
|
const inputBuffer = await fs.readFile("input.png");
|
||
|
|
||
|
// Process image with options
|
||
|
const processedBuffer = await transformer.processSpeechBubble(inputBuffer, {
|
||
|
mirror: true,
|
||
|
orientation: Orientation.LEFT,
|
||
|
});
|
||
|
|
||
|
// Save processed image
|
||
|
await transformer.processAndSave(inputBuffer, "output.png", {
|
||
|
mirror: true,
|
||
|
orientation: Orientation.LEFT,
|
||
|
});
|
||
|
}
|
||
|
```
|
||
|
|
||
|
## API
|
||
|
|
||
|
### `createSpeechBubbleTransformer(assetsDir?: string)`
|
||
|
|
||
|
- Creates a transformer instance
|
||
|
- `assetsDir`: Optional path to custom assets directory
|
||
|
|
||
|
### `processSpeechBubble(inputBuffer, options)`
|
||
|
|
||
|
- Applies speech bubble effect to image
|
||
|
- Options:
|
||
|
- `mirror`: Flip horizontally
|
||
|
- `orientation`: Rotate speech bubble
|
||
|
- `speechBubblePath`: Custom speech bubble image
|
||
|
|
||
|
### `processAndSave(inputBuffer, outputPath, options)`
|
||
|
|
||
|
- Processes and saves image in one step
|
||
|
|
||
|
## Supported Formats
|
||
|
|
||
|
- .png, .jpg, .jpeg, .gif, .bmp, .webp, .tiff
|
||
|
|
||
|
## Development
|
||
|
|
||
|
### Setup
|
||
|
|
||
|
1. Clone the repository
|
||
|
2. Install dependencies:
|
||
|
|
||
|
```bash
|
||
|
npm install
|
||
|
```
|
||
|
|
||
|
### Scripts
|
||
|
|
||
|
- `npm run build`: Compile TypeScript
|
||
|
- `npm run lint`: Run ESLint
|
||
|
- `npm test`: Run Jest tests
|
||
|
- `npm run test:coverage`: Run tests with coverage report
|
||
|
|
||
|
### Publishing to NPM
|
||
|
|
||
|
1. Ensure you're logged into NPM:
|
||
|
|
||
|
```bash
|
||
|
npm login
|
||
|
```
|
||
|
|
||
|
2. Update version (use appropriate semver):
|
||
|
|
||
|
```bash
|
||
|
npm version patch # or minor/major
|
||
|
```
|
||
|
|
||
|
3. Publish:
|
||
|
|
||
|
```bash
|
||
|
npm publish
|
||
|
```
|
||
|
|
||
|
### Continuous Integration
|
||
|
|
||
|
- Ensure `.github/workflows/ci.yml` is set up for automated testing
|
||
|
- Configure NPM token in repository secrets
|