golang gographics / imagickをつかってgolangで画像をresizeする
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了golang gographics / imagickをつかってgolangで画像をresizeする相关的知识,希望对你有一定的参考价值。
package main
import "github.com/gographics/imagick/imagick"
func main() {
imagick.Initialize()
defer imagick.Terminate()
mw := imagick.NewMagickWand()
defer mw.Destroy()
if err := mw.ReadImage("2015-09-11_15-34-51.jpg"); err != nil {
panic(err.Error())
}
w := mw.GetImageWidth()
h := mw.GetImageHeight()
if err := mw.ResizeImage(w/10, h/10, imagick.FILTER_LANCZOS, 1); err != nil {
panic(err.Error())
}
mw.WriteImage("resized.jpg")
}
json [Golang] golang #golang #snippets中有用的片段
[ fmt ](https://golang.org/pkg/fmt/)
-------
Print any `type`(struct,maps,primitives) with the `key` name
```
fmt.Printf("\n [key] :%+v \n", [value])
```
Print Error
```
fmt.Errorf(" \nError: %s", err.Error())
```
[ log ](https://golang.org/pkg/log/)
-------------
Print any `type`(struct,maps,primitives) with the `key` name
```
log.Printf("\n [key] :%+v \n", [value])
```
[ http ](https://golang.org/pkg/log/)
-------------
http middleware
```
func [middlewareName](h http.Handler) http.Handler {
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
// Do things before request
nextMiddleware.ServeHTTP(w, r)
// Do things after request
})
}
```
{
"http Middleware declaration": {
"prefix": "md",
"body": ["func $1(${2:nextMiddleware} http.Handler) http.Handler {\n\treturn http.HandlerFunc(func(${3:w} http.ResponseWriter, ${4:r} *http.Request) {\n\t $5\n\t nextMiddleware.ServeHTTP(${3:w}, ${4:r})\n\t $6\n\t})\n}"],
"description": "Snippet for http middleware declaration"
},
"log.Printf()": {
"prefix": "lf",
"body": [
"log.Printf(\"\\n## ${1:text} ##: %+v\\n\", ${2:value})"
],
"description": "log.Printf()"
},
"fmt.Printf()": {
"prefix": "ff",
"body": [
"fmt.Printf(\"\\n## ${1:text} ## :%+v \\n\", ${2:value})",
],
"description": "log.Printf()"
}
}
以上是关于golang gographics / imagickをつかってgolangで画像をresizeする的主要内容,如果未能解决你的问题,请参考以下文章
golang编写的项目,使用alpine制作镜像遇到的一个问题解决
Go初接触之imagick
Avalonia 实现平滑拖动指定控件
如何在 Windows 中安装 ImageMagick? [复制]
解决DLL load failed while importing _imaging: 找不到指定的模块。问题
摩根士丹利选出10家公司参加其多元文化创新实验室的首个全球班