Skip to content

Commit

Permalink
Added example and go report and package badges
Browse files Browse the repository at this point in the history
  • Loading branch information
dooman87 committed Dec 25, 2023
1 parent df9ecbe commit 57d91a1
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 0 deletions.
8 changes: 8 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@

# TransformImgs

[![Go Reference](https://pkg.go.dev/badge/github.com/Pixboost/transformimgs/v8.svg)](https://pkg.go.dev/github.com/Pixboost/transformimgs/v8)
![Go Report Card](https://goreportcard.com/badge/github.com/Pixboost/transformimgs/v8)
![Build Status](https://github.com/Pixboost/transformimgs/actions/workflows/action.yml/badge.svg)
[![codecov](https://codecov.io/gh/Pixboost/transformimgs/branch/main/graph/badge.svg)](https://codecov.io/gh/Pixboost/transformimgs)
[![Docker Pulls](https://img.shields.io/docker/pulls/pixboost/transformimgs)](https://hub.docker.com/r/pixboost/transformimgs/)
Expand All @@ -24,6 +26,7 @@ the latest image formats, such as WebP, AVIF, Jpeg XL, and network client hints.
* [Docker](#docker)
* [Options](#options)
* [Running Locally From Source Code](#running-from-source-code)
* [Using from Go Web Application](#using-from-go-web-application)
- [SaaS](#saas)
- [Performance tests](#performance-tests)
- [Opened tickets for images related features](#opened-tickets-for-images-related-features)
Expand Down Expand Up @@ -120,6 +123,11 @@ $ cd transformimgs
$ ./run.sh
```

### Using from Go Web Application

You could also easily plugin HTTP route into your existing web application
using service.GetRouter method. Here is a quick [example of how to do that](./example_test.go).

## SaaS

We run SaaS version at [pixboost.com](https://pixboost.com?source=github) with generous free tier.
Expand Down
40 changes: 40 additions & 0 deletions example_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
package transformimgs_test

import (
"fmt"
"github.com/Pixboost/transformimgs/v8/img"
"github.com/Pixboost/transformimgs/v8/img/loader"
"github.com/Pixboost/transformimgs/v8/img/processor"
"log"
"net/http"
"net/http/httptest"
"runtime"
)

func Example() {
l := &loader.Http{}
p, err := processor.NewImageMagick("/usr/local/bin/convert", "/usr/local/bin/identify")
if err != nil {
log.Fatal(err)
}

s, err := img.NewService(l, p, runtime.NumCPU())
if err != nil {
log.Fatal(err)
}

// s.GetRouter() is ready to use in your web server
server := httptest.NewServer(s.GetRouter())
defer server.Close()

resizeApi := fmt.Sprintf("%s/img/https://raw.githubusercontent.com/Pixboost/transformimgs/main/quickstart/site/img/parrot-lossy.jpg/resize?size=600", server.URL)
resp, err := http.Get(resizeApi)
if err != nil {
log.Fatal(err)
}

fmt.Println(resp.Status)

// Output:
// 200 OK
}

0 comments on commit 57d91a1

Please sign in to comment.