Skip to content

image/gif: bounds offset reversed when encoding #30887

@splace

Description

@splace

go 1.12.1 linux/amd64

What did you expect to see?

image shift not depending on saved format.

What did you see instead?

gif image shifted in the opposite direction to all other formats.

(several other image format generating libs tried and gif the only one in disagreement.)

demo example:

package main
import "image"
import "image/png"
import "image/jpeg"
import "image/gif"
import "os"

type offsetImage struct{
	image.Image
	Rect image.Rectangle	
}

func (i offsetImage) Bounds() image.Rectangle{
	return i.Rect
}

func main() {
	img:=offsetImage{image.Rect(0,0,50,50),image.Rect(0,0,50,50) }
	w,_:= os.Create("1.png")
	png.Encode(w,img)
	w,_= os.Create("1.jpg")
	jpeg.Encode(w,img,nil)
	w,_= os.Create("1.gif")
	gif.Encode(w,img,nil)
	
	img.Rect=image.Rect(30,30,80,80)  // same size just offset

	w,_= os.Create("2.png")
	png.Encode(w,img)
	w,_= os.Create("2.jpg")
	jpeg.Encode(w,img,nil)
	w,_= os.Create("2.gif")
	gif.Encode(w,img,nil)
	
}

output

without shift:all white, all the same as expected

  • 1
  • 1
  • 1

with shift:

  • 2
  • 2
  • 2

(png image above not showing in github md?)

Metadata

Metadata

Assignees

No one assigned

    Labels

    FrozenDueToAgeNeedsDecisionFeedback is required from experts, contributors, and/or the community before a change can be made.

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions