Commit 24466c70 authored by santiaago's avatar santiaago
Browse files

format with be handled by url param not extension.

parent dc447248
Loading
Loading
Loading
Loading
+9 −8
Original line number Diff line number Diff line
@@ -16,20 +16,21 @@ You can set the HTML source of the image to point directly to **tinygraphs.com**

        <img src="http://tinygraphs.com/checkerboard">

## formats
The default format is `JPEG`. You can specify the format by using the extension `.jpeg` or `.svg`
## parameters:

### size:

`tinygraphs.com/squares/hello?size=60`

### formats
The default format is `JPEG`.

Supported formats are:
* JPEG
* SVG

`tinygraphs.com/squares/hello.svg`
`tinygraphs.com/squares/hello?fmt=svg`

## parameters:

###size:

`tinygraphs.com/squares/hello?size=60`

### background and foreground:
You can specify the color of the background or foreground by using parameters `bg` and `fg` and passing an hexadecimal value of the color:
+7 −17
Original line number Diff line number Diff line
@@ -6,7 +6,6 @@ import (
	"github.com/taironas/tinygraphs/format"
	"image/color"
	"net/http"
	"path"
	"strconv"
	"strings"
)
@@ -46,23 +45,14 @@ func Size(r *http.Request) int {
}

func Format(r *http.Request) format.Format {
	// strFmt := strings.ToLower(r.FormValue("fmt"))
	// if len(strFmt) > 0 {
	// 	if strFmt == "svg" {
	// 		return format.SVG
	// 	} else if strFmt == "jpeg" || strFmt == "jpg" {
	// 		return format.JPEG
	// 	}
	// }
	strFmt := strings.ToLower(path.Ext(r.URL.Path))
	if strFmt != ".jpeg" && strFmt != ".jpg" && strFmt != ".svg" {
		strFmt = "jpeg"
	}
	if strFmt == ".svg" {
	strFmt := strings.ToLower(r.FormValue("fmt"))
	if len(strFmt) > 0 {
		if strFmt == "svg" {
			return format.SVG
	} else if strFmt == ".jpeg" || strFmt == ".jpg" {
		} else if strFmt == "jpeg" || strFmt == "jpg" {
			return format.JPEG
		}
	}
	return format.JPEG
}