# nano-banana
A lightweight Elixir library for efficient image processing and manipulation tasks. Simplifies common image operations with a focus on ease of use and performance.
## Installation
To install nano-banana, add it as a dependency to your `mix.exs` file:
elixir
def deps do
[
{:nano_banana, "~> 0.1.0"} # Replace with the actual version
]
end
Then, run `mix deps.get` to fetch and install the dependency.
## Usage Examples
Here are a few examples demonstrating how to use nano-banana for common image processing tasks:
**1. Resizing an Image:**
elixir
alias NanoBanana.Image
image_path = "path/to/your/image.jpg"
output_path = "path/to/resized_image.jpg"
case Image.resize(image_path, output_path, width: 200, height: 150) do
{:ok, _} ->
IO.puts("Image resized successfully!")
{:error, reason} ->
IO.puts("Error resizing image: #{reason}")
end
**2. Converting Image Format:**
elixir
alias NanoBanana.Image
image_path = "path/to/your/image.png"
output_path = "path/to/converted_image.jpg"
case Image.convert(image_path, output_path, format: :jpeg) do
{:ok, _} ->
IO.puts("Image converted successfully!")
{:error, reason} ->
IO.puts("Error converting image: #{reason}")
end
**3. Applying a Grayscale Filter:**
elixir
alias NanoBanana.Image
image_path = "path/to/your/image.bmp"
output_path = "path/to/grayscale_image.bmp"
case Image.grayscale(image_path, output_path) do
{:ok, _} ->
IO.puts("Grayscale filter applied successfully!")
{:error, reason} ->
IO.puts("Error applying grayscale filter: #{reason}")
end
**4. Cropping an Image:**
elixir
alias NanoBanana.Image
image_path = "path/to/your/image.tiff"
output_path = "path/to/cropped_image.tiff"
case Image.crop(image_path, output_path, x: 50, y: 50, width: 100, height: 100) do
{:ok, _} ->
IO.puts("Image cropped successfully!")
{:error, reason} ->
IO.puts("Error cropping image: #{reason}")
end
**5. Using the Pipe Operator for Multiple Operations:**
elixir
alias NanoBanana.Image
image_path = "path/to/your/image.gif"
output_path = "path/to/processed_image.png"
image_path
|> Image.resize(output_path, width: 300, height: 200)
|> then(fn
{:ok, _} -> Image.grayscale(output_path, output_path)
{:error, reason} -> {:error, reason}
end)
|> then(fn
{:ok, _} -> IO.puts("Image resized and converted to grayscale successfully!")
{:error, reason} -> IO.puts("Error processing image: #{reason}")
end)
## Feature Summary
* **Image Resizing:** Easily resize images to specified dimensions.
* **Format Conversion:** Convert images between various formats (JPEG, PNG, GIF, BMP, TIFF).
* **Grayscale Filter:** Apply a grayscale filter to images.
* **Image Cropping:** Crop images to a specific region.
* **Error Handling:** Provides informative error messages for debugging.
* **Simple API:** Designed for ease of use and integration.
## License
MIT License
This package is part of the nano-banana ecosystem. For advanced features and enterprise-grade tools, visit: https://supermaker.ai/image/nano-banana/