gimg

package module
v0.0.0-...-33aba19 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 23, 2019 License: Apache-2.0 Imports: 27 Imported by: 1

README

Gimg


Gimg是zimg的golang版本。

完全兼容zimg的文件目录储存格式,支持文件和类Redis协议(SSDB)储存。

环境要求:

  • 操作系统: ubuntu/debian/osx
  • golang版本: >= 1.4
  • ImageMagick版本: = 6.8.5-X

Install


Ubuntu/Debian


wget http://www.magickwand.org/download/releases/ImageMagick-6.8.5-10.tar.gz
tar zxvf ImageMagick-6.8.5-10.tar.gz
cd ImageMagick-6.8.5-10/
./configure
make & make install
ldconfig /usr/local/lib

OSX


brew install ImageMagick

安装


go get github.com/gographics/imagick/imagick
go get code.google.com/p/gcfg
go get github.com/garyburd/redigo/redis
go get github.com/Leon2012/gimg
cd $GOPATH/src/github.com/Leon2012/gimg/build/
go build -o gimg
./gimg --config=./conf/config.ini

Demo


http://182.92.189.64:8081/a258607b53444f32208e864f44a06b93

http://182.92.189.64:8081/info?md5=a258607b53444f32208e864f44a06b93

http://182.92.189.64:8081/a258607b53444f32208e864f44a06b93?w=100&h=100&x=-1&y=-1

http://182.92.189.64:8081/a258607b53444f32208e864f44a06b93?r=45

http://182.92.189.64:8081/a258607b53444f32208e864f44a06b93?g=1

http://182.92.189.64:8081/a258607b53444f32208e864f44a06b93?f=png

Documentation

Index

Constants

View Source
const (
	PROJECT_VERSION = "1.0.1"
	MAX_LINE        = 1024
	CACHE_KEY_SIZE  = 128
	RETRY_TIME_WAIT = 1000
	CACHE_MAX_SIZE  = 1048576 //1024*1024
	PATH_MAX_SIZE   = 512
)
View Source
const (
	Black = (iota + 30)
	Red
	Green
	Yellow
	Blue
	Magenta
	Cyan
	White
)

Variables

This section is empty.

Functions

This section is empty.

Types

type AppConfig

type AppConfig struct {
	System struct {
		IsDaemon    int
		Host        string
		Port        int
		Headers     string
		Etag        int
		LogOutput   string
		LogLevel    int
		LogName     string
		DisableArgs int
		Format      string
		Quality     int
	}

	Cache struct {
		Cache        int
		MemcacheHost string
		MemcachePort int
	}

	Storage struct {
		Mode         int
		SaveNew      int
		MaxSize      int
		AllowedTypes string
		ImgPath      string

		BeansdbHost string
		BeansdbPort int

		SsdbHost string
		SsdbPort int
	}
}

func LoadConfig

func LoadConfig(cfgFile string) (AppConfig, error)

type Info

type Info struct {
	Id      uint64
	Time    string
	Module  string
	Level   string
	Message string
	// contains filtered or unexported fields
}

func (*Info) Output

func (i *Info) Output() string

type Worker

type Worker struct {
	Minion  *log.Logger
	Color   int
	LogFile *os.File
}

func NewConsoleWorker

func NewConsoleWorker(prefix string, flag int, color int) *Worker

func NewFileWorker

func NewFileWorker(prefix string, flag int, color int, logFile *os.File) *Worker

func NewWorker

func NewWorker(prefix string, flag int, color int, out io.Writer) *Worker

func (*Worker) Log

func (w *Worker) Log(level string, calldepth int, info *Info) error

type ZBaseStorage

type ZBaseStorage struct {
	// contains filtered or unexported fields
}

type ZCache

type ZCache struct {
	// contains filtered or unexported fields
}

func NewCache

func NewCache(h string, p int) *ZCache

func (*ZCache) DelCache

func (z *ZCache) DelCache(key string) error

func (*ZCache) Exist

func (z *ZCache) Exist(key string) bool

func (*ZCache) FindCache

func (z *ZCache) FindCache(key string) (string, error)

func (*ZCache) FindCacheBin

func (z *ZCache) FindCacheBin(key string) ([]byte, error)

func (*ZCache) ReTry

func (z *ZCache) ReTry()

func (*ZCache) SetCache

func (z *ZCache) SetCache(k string, v string) error

func (*ZCache) SetCacheBin

func (z *ZCache) SetCacheBin(k string, v []byte) error

type ZContext

type ZContext struct {
	Config AppConfig
	Logger *ZLogger
	Cache  *ZCache
	Image  *ZImage
	Redis  *ZRedisDB
}

func NewContext

func NewContext(cfgFile string) (*ZContext, error)

func (*ZContext) Release

func (z *ZContext) Release()

type ZFileStorage

type ZFileStorage struct {
	sync.RWMutex
	*ZBaseStorage
	// contains filtered or unexported fields
}

func NewFileStorage

func NewFileStorage(c *ZContext) *ZFileStorage

func (*ZFileStorage) GetImage

func (z *ZFileStorage) GetImage(request *ZRequest) ([]byte, error)

func (*ZFileStorage) InfoImage

func (z *ZFileStorage) InfoImage(md5 string) (*ZImageInfo, error)

func (*ZFileStorage) NewImage

func (z *ZFileStorage) NewImage(saveName string, data []byte) error

func (*ZFileStorage) SaveImage

func (z *ZFileStorage) SaveImage(data []byte) (string, error)

type ZHttpd

type ZHttpd struct {
	// contains filtered or unexported fields
}

func NewHttpd

func NewHttpd(c *ZContext) *ZHttpd

func (*ZHttpd) ServeHTTP

func (z *ZHttpd) ServeHTTP(w http.ResponseWriter, r *http.Request)

type ZImage

type ZImage struct {
	MW *imagick.MagickWand
}

func NewImage

func NewImage() *ZImage

func (*ZImage) Destroy

func (z *ZImage) Destroy()

type ZImageInfo

type ZImageInfo struct {
	Size    int    `json:"size"`
	Width   int    `json:"width"`
	Height  int    `json:"height"`
	Quality int    `json:"quality"`
	Format  string `json:"format"`
}

type ZLogger

type ZLogger struct {
	Module string
	Worker *Worker
}

func NewDailyLogger

func NewDailyLogger(module string, color int, logPath string) (*ZLogger, error)

func NewFileLogger

func NewFileLogger(module string, color int, logFile string) (*ZLogger, error)

func NewLogger

func NewLogger(module string, color int) (*ZLogger, error)

func (*ZLogger) Close

func (l *ZLogger) Close()

func (*ZLogger) Critical

func (l *ZLogger) Critical(format string, v ...interface{})

func (*ZLogger) Debug

func (l *ZLogger) Debug(format string, v ...interface{})

func (*ZLogger) Error

func (l *ZLogger) Error(format string, v ...interface{})

func (*ZLogger) Fatal

func (l *ZLogger) Fatal(format string, v ...interface{})

func (*ZLogger) Info

func (l *ZLogger) Info(format string, v ...interface{})

func (*ZLogger) Log

func (l *ZLogger) Log(lvl string, message string)

func (*ZLogger) Notice

func (l *ZLogger) Notice(format string, v ...interface{})

func (*ZLogger) Panic

func (l *ZLogger) Panic(format string, v ...interface{})

func (*ZLogger) Strack

func (l *ZLogger) Strack(format string, v ...interface{})

func (*ZLogger) Warning

func (l *ZLogger) Warning(format string, v ...interface{})

type ZRedisDB

type ZRedisDB struct {
	// contains filtered or unexported fields
}

func NewRedisDB

func NewRedisDB(s string, p int) (*ZRedisDB, error)

func (*ZRedisDB) Close

func (z *ZRedisDB) Close()

func (*ZRedisDB) Do

func (z *ZRedisDB) Do(commandName string, args ...interface{}) (interface{}, error)

func (*ZRedisDB) Exist

func (z *ZRedisDB) Exist(key string) bool

func (*ZRedisDB) Flush

func (z *ZRedisDB) Flush()

func (*ZRedisDB) Get

func (z *ZRedisDB) Get(key string) ([]byte, error)

func (*ZRedisDB) Send

func (z *ZRedisDB) Send(commandName string, args ...interface{}) error

type ZRequest

type ZRequest struct {
	Md5        string
	ImageType  string
	Width      int
	Height     int
	Proportion int
	Gary       int
	X          int
	Y          int
	Rotate     int
	Format     string
	Save       int
	Quality    int
}

type ZSSDBStorage

type ZSSDBStorage struct {
	*ZBaseStorage
}

func NewSSDBStorage

func NewSSDBStorage(c *ZContext) *ZSSDBStorage

func (*ZSSDBStorage) GetImage

func (z *ZSSDBStorage) GetImage(request *ZRequest) ([]byte, error)

func (*ZSSDBStorage) InfoImage

func (z *ZSSDBStorage) InfoImage(md5 string) (*ZImageInfo, error)

func (*ZSSDBStorage) SaveImage

func (z *ZSSDBStorage) SaveImage(data []byte) (string, error)

type ZStorage

type ZStorage interface {
	SaveImage(data []byte) (string, error)
	//NewImage(saveName string, data []byte) error
	GetImage(request *ZRequest) ([]byte, error)
	InfoImage(md5 string) (*ZImageInfo, error)
}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL