惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

cs.AI updates on arXiv.org
cs.AI updates on arXiv.org
Hacker News - Newest:
Hacker News - Newest: "LLM"
NISL@THU
NISL@THU
Know Your Adversary
Know Your Adversary
The Hacker News
The Hacker News
D
Docker
Scott Helme
Scott Helme
有赞技术团队
有赞技术团队
罗磊的独立博客
A
Arctic Wolf
P
Privacy International News Feed
Google DeepMind News
Google DeepMind News
Spread Privacy
Spread Privacy
B
Blog
A
About on SuperTechFans
L
LINUX DO - 最新话题
博客园 - 司徒正美
T
The Blog of Author Tim Ferriss
P
Proofpoint News Feed
W
WeLiveSecurity
Exploit-DB.com RSS Feed
Exploit-DB.com RSS Feed
Google DeepMind News
Google DeepMind News
aimingoo的专栏
aimingoo的专栏
T
The Exploit Database - CXSecurity.com
美团技术团队
J
Java Code Geeks
Cloudbric
Cloudbric
雷峰网
雷峰网
Vercel News
Vercel News
P
Proofpoint News Feed
Webroot Blog
Webroot Blog
Security Archives - TechRepublic
Security Archives - TechRepublic
人人都是产品经理
人人都是产品经理
Martin Fowler
Martin Fowler
G
Google Developers Blog
T
Tenable Blog
PCI Perspectives
PCI Perspectives
Engineering at Meta
Engineering at Meta
cs.CL updates on arXiv.org
cs.CL updates on arXiv.org
H
Hackread – Cybersecurity News, Data Breaches, AI and More
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
博客园_首页
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
Apple Machine Learning Research
Apple Machine Learning Research
C
Cybersecurity and Infrastructure Security Agency CISA
S
Secure Thoughts
N
News and Events Feed by Topic
GbyAI
GbyAI
S
SegmentFault 最新的问题
cs.CV updates on arXiv.org
cs.CV updates on arXiv.org

Inside Nutrient

A guide to the invisible work behind documents Introducing Nutrient Documents for Salesforce: Native document generation and signing Document AI vs. traditional OCR: Choosing between OCR, AI, and hybrid pipelines PDF SDK compliance and security evaluation checklist for enterprise teams (2026) Invariant Corp replaces paper processes with Nutrient Workflow and scales without limits What is process mapping? A complete guide Nutrient vs. Conga Composer for Salesforce document generation (2026) Document routing: How to automate document distribution The CTO’s AI playbook: Why accountability architecture beats orchestration Compliance workflow automation: Why built-in compliance is table stakes Workflow diagrams: Examples, symbols, and how to build one that actually runs Digital forms: Replace paper forms with automated workflows Approval workflow software: How to automate approvals Why document-centric automation is different The CEO’s AI playbook: Why decision architecture beats model selection Nutrient SDK product updates for Q1 2026 PDF redaction verification: How to prove sensitive data is permanently removed What is a VPAT? The complete guide to accessibility conformance reports What is PDF/UA? The accessible PDF standard explained Salesforce eSignatures: Generate, sign, and track documents in one flow Online document viewer: Options, tradeoffs, and how to embed one Document viewer for web apps: React, Vue, Angular (2026) Best document viewers in 2026: A buyer’s guide How to edit a PDF in Python: Add text, images, and annotations Nutrient advances Workflow platform with agentic AI for enterprise-grade speed and consistency in document-heavy operations How to create a Salesforce quote template from opportunity data The business case for accessibility: Five ways it drives enterprise value Python PDF library comparison (2026): 7 libraries for developers Why your AI agent hallucinates PDF table data PDF.js limitations: When to upgrade to a commercial PDF SDK How Subject scaled 5× with Nutrient’s PDF SDK without rebuilding its document layer I replaced our sales training with an AI coach that runs in Slack — here’s what broke Redirecting to: https://securitybuzz.com/cybersecurity-news/why-enterprise-permissions-are-ais-most-dangerous-inheritance/ Nutrient .NET SDK vs. iText Core: Complete comparison for .NET developers DocuVieware: Support’s most frequently asked setup questions Introducing Nutrient Workflow How to convert PDF to Word in C# (.NET) When email and spreadsheets stop working: Work order approval workflows for field teams on the move Compliance with confidence: Why document-centric automation is the foundation of your mission Nutrient expands AI Assistant, automating multistep document workflows inside any application What is document generation? A developer’s guide to PDF generation Document Converter data flow and how real-time watermarks skip the queue PDF/UA compliance guide: Requirements, standards, and best practices Computers still can’t understand you How Athena Intelligence built AI agents for regulated enterprises with Nutrient’s document infrastructure How to convert HTML to PDF (2026): 4 methods from browser print to SDK How to build a document extraction pipeline with Nutrient Vision API OCR vs. intelligent document processing: Choosing the right document extraction engine Beyond OCR: How document intelligence eliminates manual processing in regulated industries Nutrient vs. IronPDF: Complete comparison for .NET developers Nutrient vs. Aspose.PDF: Complete comparison for .NET developers Redirecting to: https://fortune.com/2026/02/19/openclaw-who-is-peter-steinberger-openai-sam-altman-anthropic-moltbook/ Lufthansa Systems uses Nutrient to deliver reliable, scalable PDF rendering for pilots worldwide Nutrient vs. Syncfusion: Complete comparison for .NET developers React’s useTransition: The hook you’re probably using wrong First City Monument Bank streamlines banking processes with Nutrient Workflow Redirecting to: https://www.sdcexec.com/warehousing/automation/article/22957364/nutrient-workflow-automation-the-missing-link-in-supply-chain-efficiency The complete guide to digital signatures: PAdES, CAdES, and XAdES explained Nutrient Python SDK: Production-grade document processing for Python Introducing agentic document editing for web applications with AI Assistant Nutrient vs. QuestPDF: Complete comparison for .NET developers How we fixed the GdPicture license expiration (and what to do if you’re affected) Red team security testing with agentic AI The future of healthcare document automation Best healthcare workflow software compared Nutrient SDK product updates for Q4 2025 How Harvey scaled legal document workflows 50 percent MoM without rebuilding infrastructure HIPAA-compliant document management in hospitals How we optimized rendering performance while handling thousands of annotations in React — Part 2 Automated PII removal with Nutrient API Redirecting to: https://www.devopsdigest.com/2026-low-code-no-code-predictions Redirecting to: https://www.kmworld.com/Articles/Editorial/ViewPoints/Leaders-predict-AI-to-continue-permeating-all-aspects-of-KM-in-2026-172594.aspx What are deep agents and how do they solve complex problems? Whipping up document magic: Your easy-bake recipe for Vue and Nutrient Web SDK 🧁 What I’ve learned about product iteration planning while building SDKs Passwordless document signing: Three-layer security guide New zip folder functionality streamlines file management in Document Automation Server The keyboard shortcuts playbook: Taking control of keyboard events in Nutrient Web SDK From experienced engineer to AI beginner: My unexpected journey AI-assisted manual testing: Handling Safari’s PDF rendering and UI quirks How to keep a 20-year-old SDK up to date How we optimized rendering performance while handling thousands of annotations in React — Part 1 Nutrient announces new executive hires to accelerate next phase of growth High performance UI using web workers Automate document conversion at scale with Python and Nutrient DCS From curiosity to PLG (and AI): My journey to understanding product-led growth Prost to progress: One year as Nutrient Pigeon usage at Nutrient: Bridging native SDKs to Flutter Modernizing CI build servers: How to migrate from Chef to Ansible Unix man pages: AI-friendly documentation since 1971 Consistent hashing for even load distribution Best AI redaction APIs: Complete comparison guide for 2025 Why AI document redaction matters for modern security From coding to coordinating: How AI transformed my workflow What is intelligent document processing (IDP)? A complete guide Enterprise PDF SDKs: Best PSPDFKit (now Nutrient) alternatives Nutrient SDK product updates for Q3 2025 GdPicture support best practices Redacting sensitive data with Nutrient AI redaction API How AI is transforming the customer experience at Nutrient: From instant answers to intelligent support
Random image generation API with Elixir and Phoenix
Oghenerukevwe Henrietta Kofi · 2025-08-21 · via Inside Nutrient

Table of contents

    Random image generation API with Elixir and Phoenix

    TL;DR

    This tutorial walks you through building a simple Elixir + Phoenix API that generates random PNG images using Erlang’s EGD library. You’ll set up your environment with asdf, add dependencies, implement an image service, create a controller and endpoint, and serve images directly from your API. By the end, you’ll have a working foundation you can extend for dynamic charts, placeholders, or PDF assets.

    Until recently, I wasn’t aware of any tooling for generating images in Elixir, but while building internal tools that required millions of image attachments for PDFs, I had to figure it out. I learned a lot from that project, and decided to write a tutorial covering how to build an API for generating random images using Elixir and Phoenix.

    Document Engine helps automate creation, delivery, and management of large volumes of assets.

    Setup

    For this tutorial, use the asdf version manager to install the required versions of Elixir and Erlang.

    Next, run these commands to create and navigate to a new directory:

    $ mkdir image_generator

    $ cd image_generator

    Then, create a file named .tool-versions in the image_generator, and add the following to the file:

    elixir 1.18.4-otp-26

    erlang 26.2.2

    From within the image_generator directory in the terminal, run asdf install. This will set up the required Elixir and Erlang versions on your machine.

    Building the API

    Run these commands to set up the Phoenix project:

    $ mix archive.install hex phx_new

    $ mix phx.new image_generator_api --no-html --no-assets --no-ecto # Agree to install dependencies

    $ cd image_generator_api

    $ mix deps.get

    Modify the mix.exs file in the new image_generator_api project to include the egd dependency:

    defmodule ImageGeneratorApi.MixProject do

    #... Omitted for brevity.

    # Type `mix help deps` for examples and options.

    defp deps do

    [

    #...

    {:bandit, "~> 1.5"},

    {:egd, github: "erlang/egd"}

    ]

    end

    end

    Run mix deps.get again to install the new dependency.

    Create a new image_generator_api/lib/image_generator_api/image_service.ex file and add the following content:

    defmodule ImageGeneratorApi.ImageService do

    @moduledoc """

    Core image generation service using Erlang/EGD library

    """

    def get_random_image() do

    length = Enum.random(150..300)

    {point1, point2, color} = random_image_specs(length)

    image = :egd.create(length, length)

    color = :egd.color(color)

    shape = Enum.random([:filledRectangle, :filledEllipse])

    Kernel.apply(:egd, shape, [image, point1, point2, color])

    :egd.render(image)

    end

    def random_image_specs(points_upper_limit \\ 140) do

    # Generate 2D points 1 and 2.

    p1_x = Enum.random(50..points_upper_limit)

    p1_y = Enum.random(50..points_upper_limit)

    p2_x = Enum.random(50..points_upper_limit)

    p2_y = Enum.random(50..points_upper_limit)

    # Generate random color.

    color = {Enum.random(0..256), Enum.random(0..256), Enum.random(0..256)}

    {

    {p1_x, p1_y},

    {p2_x, p2_y},

    color

    }

    end

    end

    Then create a new image_generator_api/lib/image_generator_api_web/controllers/image_controller.ex file and add the following content:

    defmodule ImageGeneratorApiWeb.ImageController do

    use ImageGeneratorApiWeb, :controller

    alias ImageGeneratorApi.ImageService

    require Logger

    @doc """

    Generates a random image

    """

    def image(conn, _params) do

    image_data = ImageService.get_random_image()

    send_image_response(conn, image_data)

    rescue

    e ->

    Logger.error("Image generation failed: #{inspect(e)}")

    send_error_response(conn, "An error occurred while generating the image")

    end

    defp send_image_response(conn, image_data) do

    conn

    |> put_resp_content_type("image/png")

    |> put_resp_header("cache-control", "no-cache, no-store, must-revalidate")

    |> put_resp_header("pragma", "no-cache")

    |> put_resp_header("expires", "0")

    |> send_resp(200, image_data)

    end

    defp send_error_response(conn, reason) do

    conn

    |> put_status(:internal_server_error)

    |> json(%{

    error: "Image generation failed",

    reason: reason,

    timestamp: DateTime.utc_now()

    })

    end

    end

    Next, modify the router at image_generator_api/lib/image_generator_api_web/router.ex by including a new GET /api/image, like so:

    defmodule ImageGeneratorApiWeb.Router do

    use ImageGeneratorApiWeb, :router

    pipeline :api do

    plug :accepts, ["json"]

    end

    scope "/api", ImageGeneratorApiWeb do

    pipe_through :api

    get "/image", ImageController, :image

    end

    #...

    end

    Finally, start the Phoenix server locally with mix phx.server. After starting the server, in your browser, navigate to http://localhost:4000/api/image to see a new image. Reloading the page should generate a new image every time.

    Document Engine makes it easy to automate large-scale generation and delivery.

    Conclusion

    This project showed how to build a simple API for random image generation using Elixir, Phoenix, and Erlang’s EGD library(opens in a new tab). While the example was straightforward, the same approach can scale to more advanced use cases — such as generating charts, placeholders, or dynamic assets for PDFs and web applications.

    If you’re new to Elixir, this is also a great way to get hands-on experience with Phoenix and explore how Elixir can power APIs beyond the typical web or data processing workloads.

    For developers looking to take image generation further, Document Engine can help you automate the creation and delivery of large-scale image and PDF assets. Whether you’re generating millions of attachments for reports, invoices, or dynamic marketing materials, Document Engine streamlines the workflow so you can focus on building your app, not managing files.

    Want to experiment more? Try extending this project by adding parameters for image size, colors, or shapes, or integrating it into a larger Elixir system — and see how Document Engine can help scale your output seamlessly.

    Explore related topics

    Try for free Ready to get started?

    Related Development articles

    Explore more