本文整理汇总了Golang中github.com/disintegration/imaging.Save函数的典型用法代码示例。如果您正苦于以下问题:Golang Save函数的具体用法?Golang Save怎么用?Golang Save使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了Save函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Golang代码示例。
示例1: main
func main() {
const zoom = 1.0
const x, y = 0.0, 0.0
img := fractal(size, size, x, y, zoom, maxIterations)
imaging.Save(img, fmt.Sprintf("%.3f_%.3f_%.3f.png", x, y, zoom))
if !animate {
return
}
var wg sync.WaitGroup
is := make(chan int)
for procs := 0; procs < 4; procs++ {
wg.Add(1)
go func(is chan int) {
defer wg.Done()
for i := range is {
frame := fractal(size, size, x-0.03*float64(i), y-0.006*float64(i), zoom+0.12*float64(i), maxIterations)
imaging.Save(frame, fmt.Sprintf("frames/frame_%04d.png", i))
println(i)
}
}(is)
}
for i := 0; i < 1500; i++ {
is <- i
}
close(is)
wg.Wait()
}
开发者ID:jBugman,项目名称:fractals,代码行数:29,代码来源:main.go
示例2: GenerateThumbnail
func (be *Backend) GenerateThumbnail(bin string, filename string, width int, height int, crop bool) error {
f, err := be.GetFileMetaData(bin, filename)
if err != nil {
return err
}
if strings.Split(f.MIME, "/")[0] != "image" {
return errors.New("Batch job skipped: " + filename + " is not an image")
}
fpath := filepath.Join(be.filedir, bin, filename)
cachedir := filepath.Join(be.filedir, bin, ".cache")
if !isDir(cachedir) {
if err := os.Mkdir(cachedir, 0700); err != nil {
return err
}
}
dst := filepath.Join(cachedir, strconv.Itoa(width)+"x"+strconv.Itoa(height)+"-"+filename)
// Optimize to skip thumbnail generation if the thumbnail file exists
// and is newer than the file.
fi, err := os.Lstat(dst)
if err == nil {
if f.CreatedAt.After(fi.ModTime()) {
// File newer than thumbnail. Ok to generate.
} else {
// File older than thumbnail. No need to generate.
return nil
}
}
s, err := imaging.Open(fpath)
if err != nil {
return err
}
if crop {
im := imaging.Fill(s, width, height, imaging.Center, imaging.Lanczos)
err = imaging.Save(im, dst)
} else {
im := imaging.Resize(s, width, height, imaging.Lanczos)
err = imaging.Save(im, dst)
}
f.Links = be.GenerateLinks(f.Bin, f.Filename)
be.Lock()
defer be.Unlock()
id := bin + filename
delete(be.files, id)
be.files[id] = f
return err
}
开发者ID:espebra,项目名称:filebin,代码行数:53,代码来源:fs.go
示例3: editImage
func (p *program) editImage(rot Rot, folder string, list []string) error {
for _, item := range list {
filename := filepath.Join(config.FileRoot, folder, item)
fi, err := os.Stat(filename)
if err != nil {
return err
}
fullImage, err := imaging.Open(filename)
if err != nil {
return err
}
switch rot {
case RotLeft:
fullImage = imaging.Rotate90(fullImage)
case RotRight:
fullImage = imaging.Rotate270(fullImage)
case RotFlip:
fullImage = imaging.Rotate180(fullImage)
default:
return fmt.Errorf("Unknown rot value: %d", rot)
}
err = imaging.Save(fullImage, filename)
if err != nil {
return err
}
tm := fi.ModTime()
err = os.Chtimes(filename, tm, tm)
if err != nil {
return err
}
}
return p.refreshCache(folder, list)
}
开发者ID:rdterner,项目名称:photoview,代码行数:34,代码来源:editImage.go
示例4: MakeAndSaveThumbnailFromReader
// 生成并保存缩略图
func MakeAndSaveThumbnailFromReader(reader io.Reader, toFile string, w, h int) error {
tnImage, err := MakeThumbnailFromReader(reader, w, h)
if err != nil {
return err
}
return imaging.Save(tnImage, toFile)
}
开发者ID:netw0rm,项目名称:reweb,代码行数:8,代码来源:utils.go
示例5: createThumb
func (m *Manikyr) createThumb(root, parentFile string) {
img, err := openImageWhenReady(parentFile)
if err != nil {
m.EmitEvent(root, Error, parentFile, err)
return
}
localThumbs := m.ThumbDirGetter(parentFile)
_, err = os.Stat(localThumbs)
// If thumbDir does not exist...
if os.IsNotExist(err) {
// ..create it
err := os.Mkdir(localThumbs, m.thumbDirPerms)
if err != nil {
m.EmitEvent(root, Error, localThumbs, err)
return
}
} else if err != nil {
m.EmitEvent(root, Error, localThumbs, err)
return
}
// Save the thumbnail
thumb := imaging.Thumbnail(img, m.thumbWidth, m.thumbHeight, m.thumbAlgo)
thumbPath := path.Join(localThumbs, m.ThumbNameGetter(parentFile))
if err = imaging.Save(thumb, thumbPath); err != nil {
m.EmitEvent(root, Error, thumbPath, err)
return
}
m.EmitEvent(root, ThumbCreate, thumbPath, nil)
}
开发者ID:ComSecNinja,项目名称:manikyr,代码行数:32,代码来源:manikyr.go
示例6: thumbFile
func thumbFile(filePath string) {
src, _ := imaging.Open(filePath)
var dst *image.NRGBA
dst = imaging.Thumbnail(src, 48, 48, imaging.CatmullRom)
imaging.Save(dst, filePath)
}
开发者ID:zeuson,项目名称:gorevel,代码行数:7,代码来源:application.go
示例7: ProcessPhoto
func ProcessPhoto(photo *Photo) error {
origImg, err := imaging.Open(GetPhotoPath(photo, "o"))
if err != nil {
return err
}
src := imaging.Clone(origImg)
for _, sz := range PhotoSizes {
var dst image.Image
switch sz.Type {
case "thumbnail":
dst = imaging.Thumbnail(src, sz.Width, sz.Height, imaging.Lanczos)
case "fit":
dst = imaging.Fit(src, sz.Width, sz.Height, imaging.Lanczos)
}
err := imaging.Save(dst, GetPhotoPath(photo, sz.Suffix))
if err != nil {
return err
}
}
return nil
}
开发者ID:postfix,项目名称:quiet-1,代码行数:26,代码来源:processing.go
示例8: ProcessAvatar
func ProcessAvatar(user *User) error {
origImg, err := imaging.Open(GetAvatarPath(user, "o"))
if err != nil {
return err
}
src := imaging.Clone(origImg)
for _, sz := range AvatarSizes {
var dst image.Image
switch sz.Type {
case "thumbnail":
dst = imaging.Thumbnail(src, sz.Width, sz.Height, imaging.Lanczos)
case "fit":
dst = imaging.Fit(src, sz.Width, sz.Height, imaging.Lanczos)
}
err := imaging.Save(dst, GetAvatarPath(user, sz.Suffix))
if err != nil {
return err
}
}
return nil
}
开发者ID:postfix,项目名称:quiet-1,代码行数:26,代码来源:processing.go
示例9: MakeAndSaveThumbnail
// 生成并保存缩略图
func MakeAndSaveThumbnail(fromFile string, toFile string, w, h int) error {
tnImage, err := MakeThumbnail(fromFile, w, h)
if err != nil {
return err
}
return imaging.Save(tnImage, toFile)
}
开发者ID:netw0rm,项目名称:reweb,代码行数:8,代码来源:utils.go
示例10: MakeAndSaveFromReaderMaxWithMode
func MakeAndSaveFromReaderMaxWithMode(reader io.Reader, t string, toFile string, w, h int) error {
tnImage, err := MakeFromReaderMaxWithMode(reader, t, w, h)
if err != nil {
return err
}
return imaging.Save(tnImage, toFile)
}
开发者ID:netw0rm,项目名称:reweb,代码行数:7,代码来源:utils.go
示例11: main
func main() {
fmt.Println("ImgNet loading...")
netSize := []int{3, 3}
net := NewImgNet(netSize[0], netSize[1])
imgOrig, err := imaging.Open("lena-colour.png")
if err != nil {
panic(err)
}
imgFiltered, err := imaging.Open("lena-colourdiff.png")
if err != nil {
panic(err)
}
targetImg, err := imaging.Open("lena-colour.png")
if err != nil {
panic(err)
}
fmt.Println("Teaching network.")
for randcount := 0; randcount < 1000000; randcount++ {
x := rand.Intn(imgOrig.Bounds().Dx()-netSize[0]) - netSize[0]/2
y := rand.Intn(imgOrig.Bounds().Dy()-netSize[1]) - netSize[1]/2
net.FF(image.Pt(x, y), &imgOrig)
net.BP(image.Pt(x, y), &imgFiltered)
}
fmt.Println("Filtering image.")
result := net.Filter(targetImg)
imaging.Save(result, "output.png")
}
开发者ID:avesanen,项目名称:neuro,代码行数:33,代码来源:main.go
示例12: GenerateImage
func (f *File) GenerateImage(width int, height int, crop bool) error {
fpath := filepath.Join(f.TagDir, f.Filename)
s, err := imaging.Open(fpath)
if err != nil {
return err
}
if crop {
im := imaging.Fill(s, width, height, imaging.Center,
imaging.Lanczos)
err = imaging.Save(im, f.ImagePath(width, height))
} else {
im := imaging.Resize(s, width, height, imaging.Lanczos)
err = imaging.Save(im, f.ImagePath(width, height))
}
return err
}
开发者ID:denisbr,项目名称:filebin,代码行数:18,代码来源:file.go
示例13: resizePreview
func (image *Image) resizePreview(errorChan chan error, srcImage image.Image) {
size := srcImage.Bounds().Size()
ratio := float64(size.Y) / float64(size.X)
targetHeight := int(float64(widthPreview) * ratio)
dstImage := imaging.Resize(srcImage, widthPreview, targetHeight, imaging.Lanczos)
dest := "./data/images/preview/" + image.Location
errorChan <- imaging.Save(dstImage, dest)
}
开发者ID:Catorpilor,项目名称:Gophr,代码行数:9,代码来源:image.go
示例14: resizeImage
func resizeImage(filename string, size int) string {
resizedFile := filename + ".resized.png"
img, err := imaging.Open(filename)
if err != nil {
panic(err)
}
dstimg := imaging.Resize(img, size, 0, imaging.Box)
imaging.Save(dstimg, resizedFile)
return resizedFile
}
开发者ID:Daio-io,项目名称:pic-sizer,代码行数:10,代码来源:main.go
示例15: GenerateThumbnail
func (f *File) GenerateThumbnail() error {
fpath := filepath.Join(f.TagDir, f.Filename)
s, err := imaging.Open(fpath)
if err != nil {
return err
}
thumb := imaging.Fill(s, 75, 75, imaging.Center, imaging.NearestNeighbor)
err = imaging.Save(thumb, f.ThumbnailPath())
return err
}
开发者ID:jmcarbo,项目名称:filebin,代码行数:12,代码来源:file.go
示例16: main
func main() {
flag.Parse()
if len(*destination) > 0 {
err := os.MkdirAll(*destination, os.ModePerm)
if err != nil {
fmt.Printf("Unable to create destination: %s\n", err)
os.Exit(1)
}
}
extMatch := regexp.MustCompile(`\.[a-zA-Z0-9]+$`)
filelist := flag.Args()
// if len(filelist) == 0 {
// filelist = []string{"./*.*"}
// }
for _, srcArg := range filelist {
srcFilenames, err := filepath.Glob(srcArg)
if err != nil {
log.Printf("Glob error: %s\n", err)
continue
}
for _, srcFilename := range srcFilenames {
fmt.Printf("Processing [%s]... ", srcFilename)
src, err := imaging.Open(srcFilename)
if err != nil {
log.Printf("error: %s\n", err)
continue
}
dest := imaging.Grayscale(src)
extension := *output
if extension == "" {
extension = strings.TrimLeft(filepath.Ext(srcFilename), ".")
}
destFilename := extMatch.ReplaceAllString(srcFilename, "") + fmt.Sprintf("-grayscale.%s", extension)
if len(*destination) > 0 {
_, file := filepath.Split(destFilename)
destFilename = filepath.Join(*destination, file)
}
err = imaging.Save(dest, destFilename)
if err != nil {
log.Printf("error: %s\n", err)
continue
}
fmt.Printf("OK; written to %s\n", destFilename)
}
}
}
开发者ID:scjalliance,项目名称:grayscale,代码行数:50,代码来源:grayscale.go
示例17: thumbs
func thumbs(args []string, thumbSizes []int) {
if newThumbsSizes != "" {
vals := strings.Split(newThumbsSizes, ",")
thumbSizes = make([]int, len(vals))
for i := 0; i < len(vals); i++ {
numstr := strings.TrimSpace(vals[i])
if numstr == "" {
thumbSizes[i] = 0
continue
}
num, err := strconv.Atoi(numstr)
if err != nil {
log.Print(err)
continue
}
thumbSizes[i] = num
}
}
for i := 0; i < len(args); i++ {
file := args[i]
ext := filepath.Ext(file)
_, err := os.Stat(file)
if err != nil {
log.Fatal("file " + file + " is not accessible")
}
img, err := imaging.Open(file)
if err != nil {
log.Fatal(err)
}
for j := 0; j < len(thumbSizes); j++ {
if thumbSizes[j] == 0 {
continue
}
resized := imaging.Resize(img, thumbSizes[j], 0, imaging.Lanczos)
rect := resized.Bounds().Max
out := fmt.Sprintf("%s_%dx%d%s",
strings.TrimSuffix(file, ext), rect.X, rect.Y, ext)
err = imaging.Save(resized, out)
log.Println("saved " + out)
if err != nil {
log.Fatal(err)
}
}
}
}
开发者ID:chairraver,项目名称:img4hugo,代码行数:50,代码来源:img4hugo.go
示例18: rewriteImage
// Rewrite Image to disk
func rewriteImage(dst *image.NRGBA, filename string) (int, error) {
if r, _ := Exists(filename); r {
os.Remove(filename)
}
// save the image to file
if err := imaging.Save(dst, filename); err != nil {
return 0, err
}
f, err := os.Stat(filename)
if err != nil {
return 0, err
}
return int(f.Size()), err
}
开发者ID:sergeyfast,项目名称:eazyphotod,代码行数:18,代码来源:fs.go
示例19: resize
//缩放
func (this *Image) resize(filename string, w, h, s int) (string, error) {
if this.source == nil {
if err := this.open(filename); err != nil {
return "", err
}
}
var dst *image.NRGBA
dst = imaging.Resize(this.source, w, h, imaging.CatmullRom)
//取目标文件名
dstfile, err := this.dstFilename(s)
if err != nil {
return "", err
}
//保存文件
return dstfile, imaging.Save(dst, dstfile)
}
开发者ID:jango2015,项目名称:go-cms,代码行数:18,代码来源:image.go
示例20: Resize
func Resize(c *middleware.Context) {
w := c.QueryInt("width")
p := c.Req.URL.Path
color.Green("[path] %s", p)
target := strings.TrimPrefix(p, "/resize")
if strings.HasPrefix(target, "/cat/screen/") {
var id int64
fmt.Sscanf(target, "/cat/screen/%d?width=", &id)
name, e := screen(id)
if e != nil {
color.Red("%s", e)
return
}
target = name
}
savePath := "data/public/resize/" + com.ToStr(w) + "/" + target + ".jpg"
if com.IsFile(savePath) {
f, e := os.Open(savePath)
if e != nil {
color.Red("%s", e)
}
c.Resp.Header().Set("Content-Type", "image/jpeg")
io.Copy(c.Resp, f)
return
}
img, e := imaging.Open(filepath.Join("data/uploads", target))
if e != nil {
color.Red("%s", e)
return
}
i := resize.Resize(uint(w), uint(w/2), img, resize.Bilinear)
dir := filepath.Dir(target)
os.MkdirAll(filepath.Join("data/public/resize/"+com.ToStr(w)+"/", dir), 0777)
e = imaging.Save(i, savePath)
if e != nil {
color.Red("%s", e)
}
c.Resp.Header().Set("Content-Type", "image/jpeg")
e = jpeg.Encode(c.Resp, i, nil)
if e != nil {
color.Red("%s", e)
}
//c.Redirect("/public/resize/" + com.ToStr(w) + "/" + target + ".jpg")
}
开发者ID:zhuharev,项目名称:smoljanin.ru,代码行数:45,代码来源:catalog.go
注:本文中的github.com/disintegration/imaging.Save函数示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论