Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Only apis with font #2

Open
wants to merge 8 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
added API endpoints
  • Loading branch information
Garv K committed Oct 16, 2024
commit c52353816f442d11467186540cc2aa2e73829325
31 changes: 13 additions & 18 deletions api/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,17 @@

## Why a Separate API?

While Next.js provides API routes, there are several reasons for implementing a separate Express.js API for this project:
A separate Express.js API is implemented for this project to address limitations in the current browser-based implementation:

1. **Performance**: Image processing tasks can be computationally intensive. By offloading these tasks to a separate API, we prevent blocking the main Next.js server, ensuring better performance for other parts of the application.
1. **Offload Computation**: The current implementation relies on the browser for all computation, which can be resource-intensive. A separate API allows these tasks to be performed server-side.

2. **Scalability**: A separate API allows for independent scaling of the image processing service, which can be crucial as the application grows.
2. **Performance**: Image processing is computationally expensive. An API offloads this work from the client, improving overall application performance.

3. **File System Access**: Next.js API routes have limitations when it comes to file system operations, especially in serverless environments. A separate Express.js API provides more flexibility for file handling, which is essential for image processing tasks.
3. **Scalability**: A dedicated API enables independent scaling of image processing services as the application grows.

4. **Long-Running Processes**: Some image processing tasks may take longer than the typical timeout limits set by serverless functions or Next.js API routes. A separate API allows for better handling of these long-running processes.
4. **Broader Compatibility**: Server-side processing ensures the application works across various devices and browsers, regardless of their computational capabilities.

5. **Dependency Management**: The image processing libraries used (like `@imgly/background-removal-node` and `canvas`) may have specific system requirements that are easier to manage in a separate Node.js environment.
5. **Resource Management**: Certain image processing libraries and operations are better suited for a controlled server environment than a browser context.

## Running the API

Expand Down Expand Up @@ -59,6 +59,8 @@
```

**Expected Response**:

The API will save the image to the `uploads` directory and return the path to the removed background image.
```json
{
"success": true,
Expand All @@ -69,6 +71,8 @@

### 2. Preview Image API

The Preview Image API is used to add text to an image with a removed background.

**Endpoint**: `/api/preview-image`

**Method**: POST
Expand Down Expand Up @@ -100,18 +104,9 @@
```

**Expected Response**:
The API will return the preview image file directly.

## Reasons for Implementing Two Separate API Endpoints

1. **Modularity**: Separating the background removal and text addition processes allows for better code organization and maintenance.

2. **Flexibility**: Users can remove backgrounds without necessarily adding text, providing more options for image processing.

3. **Performance Optimization**: By caching or saving the background-removed images, we can reduce processing time for subsequent text additions or modifications.
The API will save the preview image to the `uploads` directory without returning the path to the preview image.

4. **Resource Management**: Background removal is typically more resource-intensive than text addition. Separating these processes allows for better resource allocation and potential optimization of each task independently.

5. **Error Handling**: With separate endpoints, it's easier to identify and handle errors specific to each process, improving the overall reliability of the application.
## Reason for Implementing Two Separate API Endpoints

6. **Future Scalability**: This architecture makes it easier to add new features or modify existing ones without affecting the entire image processing pipeline.
The main reason for separating background removal and text addition is flexibility. This allows users to make multiple attempts at formatting text without needing to remove the background each time, significantly improving efficiency and user experience.
Binary file added public/bear.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added public/cold.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added public/dog.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added public/enjoy.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added public/go.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added public/life.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added public/nature.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added public/noise.webp
Binary file not shown.
Binary file added public/open-source.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added public/pov.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added public/pressure.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added public/ride.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added public/sf.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added public/snap.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added public/vie.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added public/wow.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.