{"id":21354362,"url":"https://github.com/samestrin/image-api-netlify-edge","last_synced_at":"2025-03-16T05:21:45.933Z","repository":{"id":239676022,"uuid":"800032485","full_name":"samestrin/image-api-netlify-edge","owner":"samestrin","description":"A TypeScript Netlify Edge Function based REST image manipulation API using Deno, ImageMagick and multiParser.","archived":false,"fork":false,"pushed_at":"2024-05-14T21:02:14.000Z","size":76,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-01-22T17:46:52.084Z","etag":null,"topics":["api","edge-functions","image","netlify","netlify-edge-functions","rest"],"latest_commit_sha":null,"homepage":"http://image-api-edge-function-demo.netlify.app","language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/samestrin.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2024-05-13T15:14:46.000Z","updated_at":"2024-05-14T21:02:17.000Z","dependencies_parsed_at":"2024-05-14T01:32:05.807Z","dependency_job_id":"5d6c2dda-fad4-44ac-ab7f-37e99ac1d18a","html_url":"https://github.com/samestrin/image-api-netlify-edge","commit_stats":null,"previous_names":["samestrin/image-api-netlify-edge"],"tags_count":1,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/samestrin%2Fimage-api-netlify-edge","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/samestrin%2Fimage-api-netlify-edge/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/samestrin%2Fimage-api-netlify-edge/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/samestrin%2Fimage-api-netlify-edge/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/samestrin","download_url":"https://codeload.github.com/samestrin/image-api-netlify-edge/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":243828095,"owners_count":20354433,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["api","edge-functions","image","netlify","netlify-edge-functions","rest"],"created_at":"2024-11-22T04:13:13.558Z","updated_at":"2025-03-16T05:21:45.914Z","avatar_url":"https://github.com/samestrin.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# image-api-netlify-edge\n\n[![Star on GitHub](https://img.shields.io/github/stars/samestrin/image-api-netlify-edge?style=social)](https://github.com/samestrin/image-api-netlify-edge/stargazers)[![Fork on GitHub](https://img.shields.io/github/forks/samestrin/image-api-netlify-edge?style=social)](https://github.com/samestrin/image-api-netlify-edge/network/members)[![Watch on GitHub](https://img.shields.io/github/watchers/samestrin/image-api-netlify-edge?style=social)](https://github.com/samestrin/image-api-netlify-edge/watchers)\n\n![Version 0.0.1](https://img.shields.io/badge/Version-0.0.1-blue)[![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)[![Built with Node.js](https://img.shields.io/badge/Built%20with-TypeScript-green)](https://www.typescriptlang.org/)\n\n**image-api-netlify-edge** is a collection of serverless functions for various image processing tasks hosted on Netlify's Edge platform. While Netlify Edge Functions are known for low latency and efficiency, this project aims to explore their capabilities with demanding, resource-intensive workloads. Leveraging Deno and ImageMagick, it covers tasks like image analysis, conversion, cropping, resizing, and thumbnail generation while exploring how far Netlify Edge Functions can go within their resource constraints when tackling potentially intensive image processing operations.\n\n### **Netlify Edge Functions**\n\nEdge functions have limits for their size and the amount of memory and execution time they can use:\n\n- **Code size limit**: 20 MB after compression. This is the maximum edge function bundle size supported.\n- **Memory per set of deployed edge functions**: 512 MB\n- **CPU execution time per request**: _50 ms_. This tracks all time spent running your scripts. Execution time does not include time spent waiting for resources or responses.\n- **Response header timeout**: 40 s\n\nWhile resource-limited, Netlify provides **_1M/month requests to edge functions per site at the free tier_**. Pro members have _2M/month requests_.\n\n### **Features**\n\n- **Analyze Image**: Computes the brightness and histogram of an image.\n- **Convert Image**: Converts images to different formats.\n- **Crop Image**: Crops images based on specified dimensions.\n- **Edge Enhance**: Enhances the edges of an image.\n- **Generate Thumbnail**: Creates thumbnails from images with specified dimensions.\n- **Image Dimensions**: Extracts the dimensions of various image formats.\n- **Resize Image**: Resizes images while maintaining aspect ratio.\n\n### **Dependencies**\n\n- **Node.js**: The script runs in a Node.js environment.\n- **Deno**: A secure runtime for JavaScript and TypeScript, used for running the edge functions.\n- **Netlify Edge Functions**: Serverless functions that run at the edge, closer to your users.\n- **ImageMagick**: For performing image manipulations.\n- **multiParser**: For parsing multipart form data.\n\n### **Installation**\n\nTo set up the project locally, follow these steps:\n\n1.  **Clone the Repository**:\n\n```bash\ngit clone https://github.com/samestrin/image-api-netlify-edge.git\ncd image-api-netlify-edge\n```\n\n2.  **Install Dependencies**: Ensure you have the required dependencies installed. Use npm or yarn to install any necessary packages.\n\n```bash\nnpm install\n```\n\n3.  **Set Up Netlify CLI**: Install the Netlify CLI to deploy and test the functions locally.\n\n```bash\n\nnpm install -g netlify-cli\n```\n\n4.  **Run the Functions Locally**: Use the Netlify CLI to run the edge functions locally.\n\n```bash\nnetlify dev\n```\n\n### **Configuration**\n\nThe `netlify.toml` file contains the configuration for the edge functions. Each function is mapped to a specific endpoint:\n\n```toml\n[build]\n  publish = \"public\"\n\n[[edge_functions]]\n  function = \"image-dimensions\"\n  path = \"/api/image-dimensions\"\n\n[[edge_functions]]\n  function = \"convert-image\"\n  path = \"/api/convert-image\"\n\n[[edge_functions]]\n  function = \"generate-thumbnail\"\n  path = \"/api/generate-thumbnail\"\n\n[[edge_functions]]\n  function = \"analyze-image\"\n  path = \"/api/analyze-image\"\n\n[[edge_functions]]\n  function = \"crop-image\"\n  path = \"/api/crop-image\"\n\n[[edge_functions]]\n  function = \"resize-image\"\n  path = \"/api/resize-image\"\n\n[[edge_functions]]\n  function = \"edge-enhance\"\n  path = \"/api/edge-enhance\"\n```\n\n## Endpoints\n\n### Analyze Image\n\n**Endpoint:** `/api/analyze-image`  \n**Method:** POST\n\nAnalyzes an image to compute its brightness and histogram.\n\n- `file`: The image file to be analyzed.\n\n#### Example Usage\n\nUse a tool like Postman or curl to make a request:\n\n```bash\ncurl -X POST \\\n    https://image-api-edge-function-demo.netlify.app/api/analyze-image \\\n    -F 'file=@/path/to/image.jpg'\n```\n\nThe server responds with:\n\n    {\n      \"brightness\": 123.45,\n      \"histogram\": {\n        \"255,255,255\": 100,\n        \"0,0,0\": 50,\n        ...\n      }\n    }\n\n### Convert Image\n\n**Endpoint:** `/api/convert-image`  \n**Method:** POST\n\nConverts an image to a specified format.\n\n- `file`: The image file to be converted.\n- `targetFormat`: The desired target format (e.g., `png`, `jpeg`).\n\n#### Example Usage\n\nUse a tool like Postman or curl to make a request:\n\n```bash\ncurl -X POST \\\n    https://image-api-edge-function-demo.netlify.app/api/convert-image \\\n    -F 'file=@/path/to/image.jpg' \\\n    -F 'targetFormat=png'\n```\n\nThe server responds with the converted image file.\n\n### Crop Image\n\n**Endpoint:** `/api/crop-image`  \n**Method:** POST\n\nCrops an image based on the specified dimensions.\n\n- `file`: The image file to be cropped.\n- `x`: The x-coordinate of the top-left corner.\n- `y`: The y-coordinate of the top-left corner.\n- `width`: The width of the cropped area.\n- `height`: The height of the cropped area.\n\n#### Example Usage\n\nUse a tool like Postman or curl to make a request:\n\n```bash\ncurl -X POST \\\n    https://image-api-edge-function-demo.netlify.app/api/crop-image \\\n    -F 'file=@/path/to/image.jpg' \\\n    -F 'x=10' \\\n    -F 'y=10' \\\n    -F 'width=100' \\\n    -F 'height=100'\n```\n\nThe server responds with the cropped image file.\n\n### Edge Enhance\n\n**Endpoint:** `/api/edge-enhance`  \n**Method:** POST\n\nEnhances the edges of an image.\n\n- `file`: The image file to be processed.\n\n#### Example Usage\n\nUse a tool like Postman or curl to make a request:\n\n```bash\ncurl -X POST \\\n    https://image-api-edge-function-demo.netlify.app/api/edge-enhance \\\n    -F 'file=@/path/to/image.jpg'\n```\n\nThe server responds with the edge-enhanced image file.\n\n### Generate Thumbnail\n\n**Endpoint:** `/api/generate-thumbnail`  \n**Method:** POST\n\nGenerates a thumbnail from an image with specified dimensions.\n\n- `file`: The image file to be used for generating the thumbnail.\n- `width`: The width of the thumbnail.\n- `height`: The height of the thumbnail.\n\n#### Example Usage\n\nUse a tool like Postman or curl to make a request:\n\n```bash\ncurl -X POST \\\n    https://image-api-edge-function-demo.netlify.app/api/generate-thumbnail \\\n    -F 'file=@/path/to/image.jpg' \\\n    -F 'width=100' \\\n    -F 'height=100'\n```\n\nThe server responds with the generated thumbnail image.\n\n### Image Dimensions\n\n**Endpoint:** `/api/image-dimensions`  \n**Method:** POST\n\nExtracts the dimensions of an image.\n\n- `file`: The image file to be analyzed.\n\n#### Example Usage\n\nUse a tool like Postman or curl to make a request:\n\n```bash\ncurl -X POST \\\n    https://image-api-edge-function-demo.netlify.app/api/image-dimensions \\\n    -F 'file=@/path/to/image.jpg'\n```\n\nThe server responds with:\n\n    {\n      \"filename\": \"image.jpg\",\n      \"dimensions\": {\n        \"width\": 800,\n        \"height\": 600\n      }\n    }\n\n### Resize Image\n\n**Endpoint:** `/api/resize-image`  \n**Method:** POST\n\nResizes an image while maintaining the aspect ratio.\n\n- `file`: The image file to be resized.\n- `width`: The desired width of the resized image.\n- `height`: The desired height of the resized image.\n\n#### Example Usage\n\nUse a tool like Postman or curl to make a request:\n\n```bash\ncurl -X POST \\\n    https://image-api-edge-function-demo.netlify.app/api/resize-image \\\n    -F 'file=@/path/to/image.jpg' \\\n    -F 'width=800' \\\n    -F 'height=600'\n```\n\nThe server responds with the resized image file.\n\n## Error Handling\n\nThe API handles errors gracefully and returns appropriate error responses:\n\n- **400 Bad Request**: Invalid request parameters.\n- **404 Not Found**: Resource not found.\n- **405 Method Not Allowed**: Invalid request method (not POST).\n- **500 Internal Server Error**: Unexpected server error.\n\n## Contribute\n\nContributions to this project are welcome. Please fork the repository and submit a pull request with your changes or improvements.\n\n## License\n\nThis project is licensed under the MIT License - see the LICENSE file for details.\n\n## Share\n\n[![Twitter](https://img.shields.io/badge/X-Tweet-blue)](https://twitter.com/intent/tweet?text=Check%20out%20this%20awesome%20project!\u0026url=https://github.com/samestrin/image-api-netlify-edge) [![Facebook](https://img.shields.io/badge/Facebook-Share-blue)](https://www.facebook.com/sharer/sharer.php?u=https://github.com/samestrin/image-api-netlify-edge) [![LinkedIn](https://img.shields.io/badge/LinkedIn-Share-blue)](https://www.linkedin.com/sharing/share-offsite/?url=https://github.com/samestrin/image-api-netlify-edge)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsamestrin%2Fimage-api-netlify-edge","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fsamestrin%2Fimage-api-netlify-edge","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsamestrin%2Fimage-api-netlify-edge/lists"}