Packages
grok_image_generator
1768531.555.964
Professional Elixir integration for grok-image-generator. Provides utilities for building links and integrating with https://supermaker.ai/blog/-grok-image-generator-model-on-supermaker-ai-twitterready-images-made-simple/.
Current section
Files
Jump to
Current section
Files
lib/grok_image_generator.ex
defmodule GrokImageGenerator do
@moduledoc """
Provides functions for generating image URLs for the Grok Image Generator service.
"""
@base_url "https://supermaker.ai/api/grok_image"
@doc """
Builds a Grok Image Generator URL with optional parameters.
## Examples
iex> GrokImageGenerator.build_url(text: "Hello, world!")
"https://supermaker.ai/api/grok_image?text=Hello,%20world!"
iex> GrokImageGenerator.build_url(text: "Hello", style: "vibrant", size: "large")
"https://supermaker.ai/api/grok_image?text=Hello&style=vibrant&size=large"
"""
def build_url(params) when is_list(params) do
query_string =
params
|> Enum.map(fn {key, value} ->
"#{key}=#{URI.encode(to_string(value))}"
end)
|> Enum.join("&")
"#{@base_url}?#{query_string}"
end
@doc """
Generates a URL with a specific text prompt.
## Examples
iex> GrokImageGenerator.generate_with_text("A cat wearing a hat")
"https://supermaker.ai/api/grok_image?text=A%20cat%20wearing%20a%20hat"
"""
def generate_with_text(text) when is_binary(text) do
build_url(text: text)
end
@doc """
Generates a URL with a specific style.
Acceptable styles are: vibrant, minimalist, futuristic
## Examples
iex> GrokImageGenerator.generate_with_style("vibrant", text: "A sunset")
"https://supermaker.ai/api/grok_image?style=vibrant&text=A%20sunset"
"""
def generate_with_style(style, params) when is_binary(style) and is_list(params) do
build_url([style: style] ++ params)
end
@doc """
Generates a URL with a specific image size.
Acceptable sizes are: small, medium, large
## Examples
iex> GrokImageGenerator.generate_with_size("large", text: "A mountain")
"https://supermaker.ai/api/grok_image?size=large&text=A%20mountain"
"""
def generate_with_size(size, params) when is_binary(size) and is_list(params) do
build_url([size: size] ++ params)
end
@doc """
Combines text, style, and size parameters to generate a URL.
## Examples
iex> GrokImageGenerator.generate(text: "A dog", style: "minimalist", size: "small")
"https://supermaker.ai/api/grok_image?text=A%20dog&style=minimalist&size=small"
"""
def generate(params) when is_list(params) do
build_url(params)
end
end