Code Monkey home page Code Monkey logo

fetch-image-proxy's Introduction

fetch-image-proxy

An image, an image! My Kingdom for a header image!

King Richard III, probably

Uses the wonderful npm package open-graph-scraper to fetch some image from a given URL.

Usage

I have a demo server running at https://image.letterq.org/URL_TO_FETCH_IMAGE_FROM

URL_TO_FETCH_IMAGES_FROM must be url encoded.

For example, the header image to this repo can be fetched like this: https://image.letterq.org/https%3A%2F%2Fgithub.com%2Fqcasey%2Ffetch-image-proxy

Docker Image is built automatically to run your own server.

Implementation

The package prefers open graph images, but will fall back to the first inline <img> otherwise.

This API 302 redirects requests to the found image, so you can include it (with an errorBuilder) in components like:

final String url = "https://ogp.me/";
Image.network("https://image.letterq.org/${Uri.encodeComponent(url)}",
    loadingBuilder:
        (context, child, loadingProgress) {
        if (loadingProgress == null) return child;
        return CircularProgressIndicator();
    },
    errorBuilder: (context, error, stackTrace) =>
        Text("Could not load image"),
)),

Responses are in the ~1-3 second range, depending on a number of factors. You can put an image cache like Cloudflare in front of this API to drastically improve response times after the first fetch.

What works well

URLs with premade open graph images

URLs with img tags in the html

What doesn't work

Pages that require javascript before loading any html

API Responses

  • 405 when you didn't URL encode
  • 404 when there aren't any images to fetch from the URL
  • 302 redirect to the found image

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.