{"id":22154598,"url":"https://github.com/ericflo/slimgfast","last_synced_at":"2025-07-26T06:32:51.605Z","repository":{"id":16425058,"uuid":"19176327","full_name":"ericflo/slimgfast","owner":"ericflo","description":"A Go-based dynamic image resizer.","archived":false,"fork":false,"pushed_at":"2014-04-28T03:25:15.000Z","size":2584,"stargazers_count":19,"open_issues_count":1,"forks_count":1,"subscribers_count":5,"default_branch":"master","last_synced_at":"2024-06-19T05:54:03.151Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"http://godoc.org/github.com/ericflo/slimgfast","language":"Go","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"bsd-3-clause","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/ericflo.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE.txt","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2014-04-26T12:00:47.000Z","updated_at":"2023-07-04T17:35:35.000Z","dependencies_parsed_at":"2022-09-17T00:21:37.386Z","dependency_job_id":null,"html_url":"https://github.com/ericflo/slimgfast","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ericflo%2Fslimgfast","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ericflo%2Fslimgfast/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ericflo%2Fslimgfast/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ericflo%2Fslimgfast/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/ericflo","download_url":"https://codeload.github.com/ericflo/slimgfast/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":227657560,"owners_count":17799982,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-12-02T01:49:49.735Z","updated_at":"2024-12-02T01:49:50.333Z","avatar_url":"https://github.com/ericflo.png","language":"Go","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Slimgfast\n\nSlimgfast is a library that allows you to create a scalable, efficient, dynamic\nimage origin server.\n\nAs an example, if you want an image to be resized to 640x480, you could hit the\nurl at http://127.0.0.1/my-image.jpg?w=640\u0026h=480 and slimgfast will dynamically\nresize your image to the correct dimensions, serve it, and cache it for later.\n\nSlimgfast comes with an executable which supports a baseline default, but most\nadvanced users will want to use it as a library for maximum configurability.\n\nGoDoc: http://godoc.org/github.com/ericflo/slimgfast\n\n### Pronunciation\n\nIt's pronounced like \"slimmage fast\" :)\n\n## Getting Started\n\nThe easiest way to get a copy of slimfast is to use \"go get\":\n\n    go get github.com/ericflo/slimgfast/slimgfastd\n\nIn your code you can now import the library:\n\n```go\nimport \"github.com/ericflo/slimgfast\"\n\n// For example:\nfetcher := \u0026slimgfast.ProxyFetcher{ProxyUrlPrefix: \"http://i.imgur.com\"}\n```\n\nTo see what the default executable can do, try running:\n\n    slimgfastd proxy http://i.imgur.com\n\nNow to load an image we can do:\n\n    open http://localhost:4400/EgLrnVL.jpg\n\nWith no arguments it will just proxy the original image which lives at\nhttp://i.imgur.com/EgLrnVL.jpg.  With arguments it will resize it:\n\n    open http://localhost:4400/EgLrnVL.jpg\\?w=300\\\u0026h=300\n\n## Using Slimgfast as a library\n\nThe steps for setting up a slimfast instance are fairly straightforward:\n\n* Create a **fetcher** that will know how to read images from the upstream\n  source\n* Create a list of **transformers**, or potential operations that can be\n  applied to the image (e.g. resize)\n* Instantiate an **app struct**, which collects all the fetchers and\n  transformers and handles the actual HTTP requests\n* Spin up the **groupcache** library so it knows who its peers are\n* Start the app and the http server\n\nIn fact, this is all that\n[main.go](https://github.com/ericflo/slimgfast/blob/master/slimgfastd/main.go) is doing.\n\n## Creating your own Fetcher\n\nCreating a Fetcher is straightforward, you only have to implement the Fetcher\ninteface, which means implementing the following:\n\n```go\nFetch(urlPath string, dest groupcache.Sink) error\n```\n\nSince it's really not all that much code, here's the body of the filesystem\nfetcher as an example:\n\n```go\n// FilesystemFetcher fetches images from the filesystem.\ntype FilesystemFetcher struct {\n    PathPrefix string\n}\n\n// Fetch opens and reads in the image data from the file requested by the user.\nfunc (f *FilesystemFetcher) Fetch(urlPath string, dest groupcache.Sink) error {\n    filePath := path.Clean(f.PathPrefix + urlPath)\n    data, err := ioutil.ReadFile(filePath)\n    if err != nil {\n        return err\n    }\n    dest.SetBytes(data)\n    return nil\n}\n```\n\n## Creating your own Transformer\n\nCreating a Transformer is similarly straightforward to creating a Fetcher,\nyou have to implement the Transformer interface, which has only one method:\n\n```go\nTransform(req *ImageRequest, image image.Image) (image.Image, error)\n```\n\nSo, it takes an image, and the request, and then returns the transformed image\n(or an error.)  Here's the body of the resize transformer as an example:\n\n```go\nimport (\n    \"github.com/nfnt/resize\"\n    \"image\"\n)\n\ntype TransformerResize struct{}\n\nfunc (t *TransformerResize) Transform(req *ImageRequest, image image.Image) (image.Image, error) {\n    resized := resize.Resize(\n        uint(req.Width),\n        uint(req.Height),\n        image,\n        resize.Lanczos3,\n    )\n    return resized, nil\n}\n```\n\nYou could easily write a transformer that uses ImageMagick or epeg, if you want\neither more power or more performance.  Or you could write a filter to change\nthe brightness, or the contrast, or turn it black and white, or any other\ninteresting image transformation.  Since you have access to the request,\nyou can parse the querystring with whatever semantics makes sense for your\nneeds.\n\n## I want something with commercial support\n\nYou should check out http://imgix.com/, which is a well-run startup that offers\na similar but more advanced commercial image service.\n\n## Status\n\nStatus: Very, very alpha.  It started as some code I'd written for work, but\nit ended up being more or less a complete rewrite, and this version hasn't seen\nany production traffic, ever.  I'll remove this warning when I'm more confident\nin it and have run it in production.","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fericflo%2Fslimgfast","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fericflo%2Fslimgfast","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fericflo%2Fslimgfast/lists"}