• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

Golang imaging.Rotate270函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Golang中github.com/disintegration/imaging.Rotate270函数的典型用法代码示例。如果您正苦于以下问题:Golang Rotate270函数的具体用法?Golang Rotate270怎么用?Golang Rotate270使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。



在下文中一共展示了Rotate270函数的17个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Golang代码示例。

示例1: AddImage

// AddImage examines the provided image and compares it to the images already
// stored in the map of prototype images.  If this image is unique and doesn't
// match any of the prototype images, including rotations or mirror copies, then
// it is added to the map of prototype images.
func (p *ImageSet) AddImage(img image.Image, x, y int) {
	index := y*p.stride + x
	images := make([]image.Image, 8)
	images[0] = img
	images[1] = imaging.Rotate90(img)
	images[2] = imaging.Rotate180(img)
	images[3] = imaging.Rotate270(img)
	images[4] = imaging.FlipH(img)
	images[5] = imaging.Rotate90(images[4])
	images[6] = imaging.Rotate180(images[4])
	images[7] = imaging.Rotate270(images[4])

	found := false
	firstHash := uint64(0)
	for i := 0; i < 8; i++ {
		hash := Hash(images[i])
		if i == 0 {
			firstHash = hash
		}

		if _, ok := p.protoImages[hash]; ok {
			found = true
			p.orientations[index] = byte(i)
			p.images[index] = hash
			break
		}
	}

	if !found {
		p.protoImages[firstHash] = img
		p.images[index] = firstHash
		p.orientations[index] = byte(0)
	}
}
开发者ID:marcboudreau,项目名称:sc4texture,代码行数:38,代码来源:imageset.go


示例2: Thumbnail

//Creating a thumbnail from a JPEG is straightforwards
func (p *JpegPhoto) Thumbnail(in io.ReadSeeker, longSide int) (io.ReadSeeker, string, error) {

	//first we need to read the image.
	img, _, err := image.Decode(in)
	if err != nil {
		return nil, "", err
	}
	var w, h int
	aspect := float64(p.Width) / float64(p.Height)
	if p.Width > p.Height {
		w, h = longSide, int(float64(longSide)/aspect)
	} else {
		w, h = int(float64(longSide)*aspect), longSide
	}
	//we need to do this switch twice. first to check if we need to swap width/height
	//as we resize before rotation/flip
	//then after to do the resize/flip.
	switch p.Orientation {
	case OrientedNormal90, OrientedMirror90, OrientedNormal270, OrientedMirror270:
		//flip then rotate 270
		w, h = h, w
	}
	//now create thumbnail.
	img = imaging.Thumbnail(img, w, h, imaging.Box)
	//now we need to rotate/flip it to match the ExifOrientation flag
	switch p.Orientation {
	case OrientedNormal:
		//nothing
	case OrientedMirror:
		//flip only
		img = imaging.FlipH(img)
	case OrientedNormal90:
		//rotate 90
		img = imaging.Rotate90(img)
	case OrientedMirror90:
		//flip and rotate 90
		img = imaging.FlipH(imaging.Rotate90(img))
	case OrientedNormal180:
		//rotate 180
		img = imaging.Rotate180(img)
	case OrientedMirror180:
		//flip then rotate 180
		img = imaging.FlipH(imaging.Rotate180(img))
	case OrientedNormal270:
		//rotate 270 (90 anti-clockwise)
		img = imaging.Rotate270(img)
	case OrientedMirror270:
		//flip then rotate 270
		img = imaging.FlipH(imaging.Rotate270(img))
	}
	//now re-encode
	var wr bytes.Buffer
	err = jpeg.Encode(&wr, img, nil)
	return bytes.NewReader(wr.Bytes()), "image/jpeg", err
}
开发者ID:thechriswalker,项目名称:opfs,代码行数:56,代码来源:jpeg.go


示例3: MakeThumb

func MakeThumb(r io.Reader, w, h int, orient int) ([]byte, error) {
	img, _, err := image.Decode(r)
	if err != nil {
		return nil, err
	}

	m := resize.Resize(uint(w), uint(h), img, resize.Bicubic)

	switch orient {
	case 3, 4:
		m = imaging.Rotate180(m)
	case 5, 6:
		m = imaging.Rotate270(m)
	case 7, 8:
		m = imaging.Rotate90(m)
	}

	switch orient {
	case 2, 5, 4, 7:
		m = imaging.FlipH(m)
	}

	var buf bytes.Buffer
	err = jpeg.Encode(&buf, m, nil)
	if err != nil {
		return nil, err
	}
	return buf.Bytes(), nil
}
开发者ID:rwcarlsen,项目名称:gallery,代码行数:29,代码来源:util.go


示例4: 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


示例5: transformImage

// transformImage modifies the image m based on the transformations specified
// in opt.
func transformImage(m image.Image, opt Options) image.Image {
	// resize if needed
	if w, h, resize := resizeParams(m, opt); resize {
		if opt.Fit {
			m = imaging.Fit(m, w, h, resampleFilter)
		} else {
			if w == 0 || h == 0 {
				m = imaging.Resize(m, w, h, resampleFilter)
			} else {
				m = imaging.Thumbnail(m, w, h, resampleFilter)
			}
		}
	}

	// flip
	if opt.FlipVertical {
		m = imaging.FlipV(m)
	}
	if opt.FlipHorizontal {
		m = imaging.FlipH(m)
	}

	// rotate
	switch opt.Rotate {
	case 90:
		m = imaging.Rotate90(m)
	case 180:
		m = imaging.Rotate180(m)
	case 270:
		m = imaging.Rotate270(m)
	}

	return m
}
开发者ID:LimiQS,项目名称:imageproxy,代码行数:36,代码来源:transform.go


示例6: GetRotatedImage

func GetRotatedImage(src io.Reader) (image.Image, string, error) {
	raw, err := ioutil.ReadAll(src)
	if err != nil {
		return nil, "", err
	}

	data := bytes.NewReader(raw)

	image, format, err := image.Decode(data)
	if err != nil {
		return nil, "", err
	}

	if _, err := data.Seek(0, 0); err != nil {
		return nil, "", err
	}

	angle := needsRotation(data)
	switch angle {
	case 90:
		image = imaging.Rotate90(image)
	case 180:
		image = imaging.Rotate180(image)
	case 270:
		image = imaging.Rotate270(image)
	}

	return image, format, nil
}
开发者ID:danrjohnson,项目名称:vip,代码行数:29,代码来源:manip.go


示例7: Thumbnail

//Creating a thumbnail from a mp4 is complex so I cheat and use FFMPEG to create a JPEG...
//JPEG is straightforwards
// but ffmpeg probably can't make a thumbnail from a piped reader, so this only works if our
//ReadSeeker is actually an *os.File
func (m *Mp4Video) Thumbnail(in io.ReadSeeker, longSide int) (io.ReadSeeker, string, error) {
	var cmd *exec.Cmd
	if file, ok := in.(*os.File); ok {
		//this is the best way as ffmpeg can seek.
		cmd = exec.Command("ffmpeg", "-i", "/dev/fd/3", "-vframes", "1", "-f", "image2", "-")
		cmd.ExtraFiles = []*os.File{file}
	} else {
		log.Println("mp4thumb: using stdin (will probably fail...)")
		cmd = exec.Command("ffmpeg", "-i", "-", "-vframes", "1", "-f", "image2", "-")
		cmd.Stdin = in
	}
	stdout, err := cmd.StdoutPipe()
	//cmd.Stderr = os.Stderr
	if err != nil {
		return nil, "", err
	}
	if err := cmd.Start(); err != nil {
		return nil, "", err
	}
	img, err := jpeg.Decode(stdout)
	if err != nil {
		return nil, "", err
	}
	if err := cmd.Wait(); err != nil {
		return nil, "", err
	}
	//now we should have a jpeg to resize!
	var w, h int
	aspect := float64(m.Width) / float64(m.Height)
	if m.Width > m.Height {
		w, h = longSide, int(float64(longSide)/aspect)
	} else {
		w, h = int(float64(longSide)*aspect), longSide
	}
	switch m.Orientation {
	case photo.OrientedNormal90, photo.OrientedNormal270:
		//flip then rotate 270
		w, h = h, w
	}
	//now create thumbnail.
	img = imaging.Thumbnail(img, w, h, imaging.Box)
	//rotate if needed.
	switch m.Orientation {
	case photo.OrientedNormal90:
		//rotate 90 (270 anticlockwise)
		img = imaging.Rotate270(img)
	case photo.OrientedNormal180:
		//rotate 180
		img = imaging.Rotate180(img)
	case photo.OrientedNormal270:
		//rotate 270 (90 anti-clockwise)
		img = imaging.Rotate90(img)
	}
	var wr bytes.Buffer
	err = jpeg.Encode(&wr, img, nil)
	return bytes.NewReader(wr.Bytes()), "image/jpeg", err
}
开发者ID:thechriswalker,项目名称:opfs,代码行数:61,代码来源:mp4.go


示例8: rotate

func rotate(img image.Image, orientation int) image.Image {
	fmt.Println("orientation:", orientation)
	// 1        2       3      4         5            6           7          8

	// 888888  888888      88  88      8888888888  88                  88  8888888888
	// 88          88      88  88      88  88      88  88          88  88      88  88
	// 8888      8888    8888  8888    88          8888888888  8888888888          88
	// 88          88      88  88
	// 88          88  888888  888888

	// func Rotate180(img image.Image) *image.NRGBA
	// func Rotate270(img image.Image) *image.NRGBA
	// func Rotate90(img image.Image) *image.NRGBA
	// func FlipH(img image.Image) *image.NRGBA
	// func FlipV(img image.Image) *image.NRGBA

	var out image.Image
	switch orientation {
	case 1:
		out = img
		// nothing;
	case 2:
		out = imaging.FlipH(img)
		// flip Horiz L to R
	case 3:
		out = imaging.Rotate180(img)
		// rotate 180 ccw
	case 4:
		out = imaging.FlipV(img)
		// flip Vert T to B
	case 5:
		out = imaging.Transpose(img)
		// transpose
	case 6:
		out = imaging.Rotate90(img)
		// rotate 90
	case 7:
		out = imaging.Transverse(img)
		// transverse
	case 8:
		out = imaging.Rotate270(img)
		// rotate 270
	default:
		out = img
		// nothing;
	}

	return out
}
开发者ID:zqzca,项目名称:back,代码行数:49,代码来源:thumbnail.go


示例9: handleImages

func handleImages(previewPathList []string, thumbnailPathList []string, fileData [][]byte) {
	for i, data := range fileData {
		go func(i int, data []byte) {
			// Decode image bytes into Image object
			img, imgType, err := image.Decode(bytes.NewReader(fileData[i]))
			if err != nil {
				l4g.Error(utils.T("api.file.handle_images_forget.decode.error"), err)
				return
			}

			width := img.Bounds().Dx()
			height := img.Bounds().Dy()

			// Fill in the background of a potentially-transparent png file as white
			if imgType == "png" {
				dst := image.NewRGBA(img.Bounds())
				draw.Draw(dst, dst.Bounds(), image.NewUniform(color.White), image.Point{}, draw.Src)
				draw.Draw(dst, dst.Bounds(), img, img.Bounds().Min, draw.Over)
				img = dst
			}

			// Flip the image to be upright
			orientation, _ := getImageOrientation(fileData[i])

			switch orientation {
			case UprightMirrored:
				img = imaging.FlipH(img)
			case UpsideDown:
				img = imaging.Rotate180(img)
			case UpsideDownMirrored:
				img = imaging.FlipV(img)
			case RotatedCWMirrored:
				img = imaging.Transpose(img)
			case RotatedCCW:
				img = imaging.Rotate270(img)
			case RotatedCCWMirrored:
				img = imaging.Transverse(img)
			case RotatedCW:
				img = imaging.Rotate90(img)
			}

			go generateThumbnailImage(img, thumbnailPathList[i], width, height)
			go generatePreviewImage(img, previewPathList[i], width)
		}(i, data)
	}
}
开发者ID:duzhanyuan,项目名称:platform,代码行数:46,代码来源:file.go


示例10: prepareImage

func prepareImage(fileData []byte) (*image.Image, int, int) {
	// Decode image bytes into Image object
	img, imgType, err := image.Decode(bytes.NewReader(fileData))
	if err != nil {
		l4g.Error(utils.T("api.file.handle_images_forget.decode.error"), err)
		return nil, 0, 0
	}

	width := img.Bounds().Dx()
	height := img.Bounds().Dy()

	// Fill in the background of a potentially-transparent png file as white
	if imgType == "png" {
		dst := image.NewRGBA(img.Bounds())
		draw.Draw(dst, dst.Bounds(), image.NewUniform(color.White), image.Point{}, draw.Src)
		draw.Draw(dst, dst.Bounds(), img, img.Bounds().Min, draw.Over)
		img = dst
	}

	// Flip the image to be upright
	orientation, _ := getImageOrientation(fileData)

	switch orientation {
	case UprightMirrored:
		img = imaging.FlipH(img)
	case UpsideDown:
		img = imaging.Rotate180(img)
	case UpsideDownMirrored:
		img = imaging.FlipV(img)
	case RotatedCWMirrored:
		img = imaging.Transpose(img)
	case RotatedCCW:
		img = imaging.Rotate270(img)
	case RotatedCCWMirrored:
		img = imaging.Transverse(img)
	case RotatedCW:
		img = imaging.Rotate90(img)
	}

	return &img, width, height
}
开发者ID:Rudloff,项目名称:platform,代码行数:41,代码来源:file.go


示例11: TransformImage

// Transforms image (resize, rotate, flip, brightness, contrast)
func (c *Convertor) TransformImage(img image.Image) image.Image {
	var i image.Image = img

	if c.Opts.Width > 0 || c.Opts.Height > 0 {
		if c.Opts.Fit {
			i = imaging.Fit(i, c.Opts.Width, c.Opts.Height, filters[c.Opts.Filter])
		} else {
			i = imaging.Resize(i, c.Opts.Width, c.Opts.Height, filters[c.Opts.Filter])
		}
	}

	if c.Opts.Rotate > 0 {
		switch c.Opts.Rotate {
		case 90:
			i = imaging.Rotate90(i)
		case 180:
			i = imaging.Rotate180(i)
		case 270:
			i = imaging.Rotate270(i)
		}
	}

	if c.Opts.Flip != "none" {
		switch c.Opts.Flip {
		case "horizontal":
			i = imaging.FlipH(i)
		case "vertical":
			i = imaging.FlipV(i)
		}
	}

	if c.Opts.Brightness != 0 {
		i = imaging.AdjustBrightness(i, c.Opts.Brightness)
	}

	if c.Opts.Contrast != 0 {
		i = imaging.AdjustContrast(i, c.Opts.Contrast)
	}

	return i
}
开发者ID:gen2brain,项目名称:cbconvert,代码行数:42,代码来源:cbconvert.go


示例12: thumbnailHandler

func thumbnailHandler(w http.ResponseWriter, r *http.Request) {
	query := r.URL.Query()
	height, err := strconv.Atoi(query.Get("height"))
	if err != nil {
		height = 50
	}
	path := filepath.Join(storage, r.URL.Path)
	photo, err := imaging.Open(path)
	if err != nil {
		fmt.Fprint(w, err)
		return
	}
	switch readRotation(path) {
	case 8:
		photo = imaging.Rotate90(photo)
	case 2:
		photo = imaging.Rotate180(photo)
	case 6:
		photo = imaging.Rotate270(photo)
	}
	thumb := imaging.Resize(photo, 0, height, imaging.Box)
	imaging.Encode(w, thumb, imaging.JPEG)
}
开发者ID:kraiz,项目名称:fotobrowser,代码行数:23,代码来源:main.go


示例13: storeImage


//.........这里部分代码省略.........
	bucketHandle = client.Bucket(bucketName)
	c.Infof("APP Engine Version: %s", gcsappengine.VersionID(cc))
	c.Infof("Using bucket name: %s", bucketName)

	// Change default object ACLs
	if err = bucketHandle.DefaultObjectACL().Set(cc, storage.AllUsers, storage.RoleReader); err != nil {
		c.Errorf("%v in saving default object ACL rule for bucket %q", err, bucketName)
		r = http.StatusInternalServerError
		return
	}

	// Store rotated image in Google Cloud Storage
	var in *bytes.Reader = bytes.NewReader(b)
	var x *exif.Exif = nil
	var orientation *tiff.Tag = nil
	var beforeImage image.Image
	var afterImage *image.NRGBA = nil

	// Read EXIF
	if _, err = in.Seek(0, 0); err != nil {
		c.Errorf("%s in moving the reader offset to the beginning in order to read EXIF", err)
		return
	}
	if x, err = exif.Decode(in); err != nil {
		c.Errorf("%s in decoding JPEG image", err)
		return
	}

	// Get Orientation
	if orientation, err = x.Get(exif.Orientation); err != nil {
		c.Warningf("%s in getting orientation from EXIF", err)
		return
	}
	c.Debugf("Orientation %s", orientation.String())

	// Open image
	if _, err = in.Seek(0, 0); err != nil {
		c.Errorf("%s in moving the reader offset to the beginning in order to read EXIF", err)
		return
	}
	if beforeImage, err = imaging.Decode(in); err != nil {
		c.Errorf("%s in opening image %s", err)
		return
	}

	switch orientation.String() {
	case "1":
		afterImage = beforeImage.(*image.NRGBA)
	case "2":
		afterImage = imaging.FlipH(beforeImage)
	case "3":
		afterImage = imaging.Rotate180(beforeImage)
	case "4":
		afterImage = imaging.FlipV(beforeImage)
	case "5":
		afterImage = imaging.Transverse(beforeImage)
	case "6":
		afterImage = imaging.Rotate270(beforeImage)
	case "7":
		afterImage = imaging.Transpose(beforeImage)
	case "8":
		afterImage = imaging.Rotate90(beforeImage)
	}

	// Save rotated image
	wc = bucketHandle.Object(fileName).NewWriter(cc)
	wc.ContentType = contentType
	if err = imaging.Encode(wc, afterImage, imaging.JPEG); err != nil {
		c.Errorf("%s in saving rotated image", err)
		return
	}
	if err = wc.Close(); err != nil {
		c.Errorf("CreateFile: unable to close bucket %q, file %q: %v", bucketName, fileName, err)
		r = 1
		return
	}
	wc = nil

	// Make thumbnail
	if afterImage.Rect.Dx() > afterImage.Rect.Dy() {
		afterImage = imaging.Resize(afterImage, 1920, 0, imaging.Lanczos)
	} else {
		afterImage = imaging.Resize(afterImage, 0, 1920, imaging.Lanczos)
	}

	// Save thumbnail
	wc = bucketHandle.Object(fileNameThumbnail).NewWriter(cc)
	wc.ContentType = contentType
	if imaging.Encode(wc, afterImage, imaging.JPEG); err != nil {
		c.Errorf("%s in saving image thumbnail", err)
		return
	}
	if err = wc.Close(); err != nil {
		c.Errorf("CreateFileThumbnail: unable to close bucket %q, file %q: %v", bucketName, fileNameThumbnail, err)
		r = 1
		return
	}

	c.Infof("/%v/%v, /%v/%v created", bucketName, fileName, bucketName, fileNameThumbnail)
}
开发者ID:junglesung,项目名称:Aliza,代码行数:101,代码来源:images.go


示例14: transformImage

// transformImage modifies the image m based on the transformations specified
// in opt.
func transformImage(m image.Image, opt Options) image.Image {
	// convert percentage width and height values to absolute values
	imgW := m.Bounds().Max.X - m.Bounds().Min.X
	imgH := m.Bounds().Max.Y - m.Bounds().Min.Y
	var w, h int
	if 0 < opt.Width && opt.Width < 1 {
		w = int(float64(imgW) * opt.Width)
	} else if opt.Width < 0 {
		w = 0
	} else {
		w = int(opt.Width)
	}
	if 0 < opt.Height && opt.Height < 1 {
		h = int(float64(imgH) * opt.Height)
	} else if opt.Height < 0 {
		h = 0
	} else {
		h = int(opt.Height)
	}

	// never resize larger than the original image
	if !opt.ScaleUp {
		if w > imgW {
			w = imgW
		}
		if h > imgH {
			h = imgH
		}
	}

	// resize
	if w != 0 || h != 0 {
		if opt.Fit {
			m = imaging.Fit(m, w, h, resampleFilter)
		} else {
			if w == 0 || h == 0 {
				m = imaging.Resize(m, w, h, resampleFilter)
			} else {
				m = imaging.Thumbnail(m, w, h, resampleFilter)
			}
		}
	}

	// flip
	if opt.FlipVertical {
		m = imaging.FlipV(m)
	}
	if opt.FlipHorizontal {
		m = imaging.FlipH(m)
	}

	// rotate
	switch opt.Rotate {
	case 90:
		m = imaging.Rotate90(m)
	case 180:
		m = imaging.Rotate180(m)
	case 270:
		m = imaging.Rotate270(m)
	}

	return m
}
开发者ID:victortrac,项目名称:imageproxy,代码行数:65,代码来源:transform.go


示例15: FlipDiagonal

func (i imagingFlipper) FlipDiagonal(tile image.Image) image.Image {
	return imaging.FlipH(imaging.Rotate270(tile))
}
开发者ID:manyminds,项目名称:tmx,代码行数:3,代码来源:flipper.go


示例16: main

func main() {
	fmt.Println("Hello, world")
	fname := "P1070332.JPG"
	rname := "P1070332_rotate.JPG"
	sname := "P1070332_small.JPG"

	f, err := os.Open(fname)
	if err != nil {
		log.Fatal(err)
	}
	defer f.Close()

	// Optionally register camera makenote data parsing - currently Nikon and
	// Canon are supported.
	exif.RegisterParsers(mknote.All...)

	x, err := exif.Decode(f)
	if err != nil {
		log.Fatal(err)
	}

	// Get Orientation
	orientation, err := x.Get(exif.Orientation)
	if err != nil {
		fmt.Println(exif.Model, " not fround")
		return
	}
	fmt.Println("Orientation", orientation.String())

	// Rotate
	var rotateImage *image.NRGBA
	openImage, err := imaging.Open(fname)
	if err != nil {
		fmt.Println(err)
		return
	}
	switch orientation.String() {
	case "1":
	// Do nothing
	case "2":
		rotateImage = imaging.FlipH(openImage)
	case "3":
		rotateImage = imaging.Rotate180(openImage)
	case "4":
		rotateImage = imaging.FlipV(openImage)
	case "5":
		rotateImage = imaging.Transverse(openImage)
	case "6":
		rotateImage = imaging.Rotate270(openImage)
	case "7":
		rotateImage = imaging.Transpose(openImage)
	case "8":
		rotateImage = imaging.Rotate90(openImage)
	}
	err = imaging.Save(rotateImage, rname)
	if err != nil {
		fmt.Println(err)
		return
	}
	fmt.Println(rname, " saved")

	// Small
	var smallImage *image.NRGBA
	if rotateImage.Rect.Dx() > rotateImage.Rect.Dy() {
		smallImage = imaging.Resize(rotateImage, 1920, 0, imaging.Lanczos)
	} else {
		smallImage = imaging.Resize(rotateImage, 0, 1920, imaging.Lanczos)
	}
	err = imaging.Save(smallImage, sname)
	if err != nil {
		fmt.Println(err)
		return
	}
	fmt.Println(sname, " saved")

	// Use jpeg.Encode() to write to a file
	// https://github.com/disintegration/imaging/blob/master/helpers.go#L79
	// func Encode(w io.Writer, m image.Image, o *Options) error
	// https://golang.org/pkg/image/jpeg/
}
开发者ID:junglesung,项目名称:TestGoRotateImage,代码行数:80,代码来源:main.go


示例17: handleServeImage

func handleServeImage(ctx context.Context, w http.ResponseWriter, r *http.Request) {
	img, err := ImageByID(sq.DB(ctx), web.Args(ctx).ByIndex(0))
	switch err {
	case nil:
		// all good
	case sq.ErrNotFound:
		web.StdJSONResp(w, http.StatusNotFound)
		return
	default:
		log.Error("cannot get object",
			"object", web.Args(ctx).ByIndex(0),
			"error", err.Error())
		web.StdJSONResp(w, http.StatusInternalServerError)
		return
	}

	if web.CheckLastModified(w, r, img.Created) {
		return
	}

	fs := FileStore(ctx)
	fd, err := fs.Read(img.Created.Year(), img.ImageID)
	if err != nil {
		log.Error("cannot read image file",
			"image", img.ImageID,
			"error", err.Error())
		web.StdJSONResp(w, http.StatusInternalServerError)
		return
	}
	defer fd.Close()

	w.Header().Set("X-Image-ID", img.ImageID)
	w.Header().Set("X-Image-Width", fmt.Sprint(img.Width))
	w.Header().Set("X-Image-Height", fmt.Sprint(img.Height))
	w.Header().Set("X-Image-Created", img.Created.Format(time.RFC3339))
	w.Header().Set("Content-Type", "image/jpeg")

	if r.URL.Query().Get("resize") == "" {
		io.Copy(w, fd)
		return
	}

	image, err := jpeg.Decode(fd)
	if err != nil {
		log.Error("cannot read image file",
			"image", img.ImageID,
			"error", err.Error())
		web.StdJSONResp(w, http.StatusInternalServerError)
		return
	}
	var width, height int
	if _, err := fmt.Sscanf(r.URL.Query().Get("resize"), "%dx%d", &width, &height); err != nil {
		log.Error("cannot resize image",
			"image", img.ImageID,
			"error", err.Error())
	} else {
		switch img.Orientation {
		case 1:
			// all good
		case 3:
			image = imaging.Rotate180(image)
		case 8:
			image = imaging.Rotate90(image)
		case 6:
			image = imaging.Rotate270(image)
		default:
			log.Debug("unknown image orientation",
				"decoder", "EXIF",
				"image", img.ImageID,
				"value", fmt.Sprint(img.Orientation))
		}
		image = imaging.Fill(image, width, height, imaging.Center, imaging.Linear)
	}
	imaging.Encode(w, image, imaging.JPEG)
}
开发者ID:husio,项目名称:apps,代码行数:75,代码来源:handlers.go



注:本文中的github.com/disintegration/imaging.Rotate270函数示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Golang imaging.Rotate90函数代码示例发布时间:2022-05-23
下一篇:
Golang imaging.Rotate180函数代码示例发布时间:2022-05-23
热门推荐
热门话题
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap