grok-image-generator

A Dart package that simplifies the process of generating images based on the Grok image generator model. This package provides convenient functions to integrate image generation capabilities into your Dart applications.

Installation

To use the grok-image-generator package in your Dart project, add it as a dependency in your pubspec.yaml file: yaml dependencies: grok_image_generator: ^1.0.0 # Replace with the latest version

Then, run dart pub get to install the package.

Usage

Here are some examples of how to use the grok-image-generator package:

1. Basic Image Generation: dart import 'package:grok_image_generator/grok_image_generator.dart';

void main() async { final generator = GrokImageGenerator(); final imageUrl = await generator.generateImage(prompt: "A futuristic cityscape at sunset");

if (imageUrl != null) { print("Image URL: $imageUrl"); // You can then use this URL to display the image in your app. } else { print("Image generation failed."); } }

2. Specifying Image Dimensions: dart import 'package:grok_image_generator/grok_image_generator.dart';

void main() async { final generator = GrokImageGenerator(); final imageUrl = await generator.generateImage(prompt: "A cat wearing a hat", width: 512, height: 512);

if (imageUrl != null) { print("Image URL: $imageUrl"); } else { print("Image generation failed."); } }

3. Handling Errors: dart import 'package:grok_image_generator/grok_image_generator.dart';

void main() async { final generator = GrokImageGenerator(); try { final imageUrl = await generator.generateImage(prompt: "A very complex and impossible scene");

if (imageUrl != null) {
  print("Image URL: $imageUrl");
} else {
  print("Image generation failed.");
}

} catch (e) { print("Error generating image: $e"); } }

4. Using a Custom API Key (if required): dart import 'package:grok_image_generator/grok_image_generator.dart';

void main() async { final generator = GrokImageGenerator(apiKey: "YOUR_API_KEY"); // Replace with your actual API key final imageUrl = await generator.generateImage(prompt: "A beautiful landscape");

if (imageUrl != null) { print("Image URL: $imageUrl"); } else { print("Image generation failed."); } }

5. Advanced Prompting: dart import 'package:grok_image_generator/grok_image_generator.dart';

void main() async { final generator = GrokImageGenerator(); final imageUrl = await generator.generateImage(prompt: "A photorealistic rendering of a steampunk robot, intricate details, dramatic lighting");

if (imageUrl != null) { print("Image URL: $imageUrl"); } else { print("Image generation failed."); } }

Features

  • Simple API: Easy-to-use functions for generating images.
  • Customizable Dimensions: Specify the width and height of the generated images.
  • Error Handling: Robust error handling to gracefully manage potential issues during image generation.
  • API Key Support: Option to provide a custom API key for enhanced access.
  • Prompt-Based Generation: Generate images based on descriptive text prompts.

License

MIT License

This package is part of the grok-image-generator ecosystem. For advanced features and enterprise-grade tools, visit: https://supermaker.ai/blog/-grok-image-generator-model-on-supermaker-ai-twitterready-images-made-simple/