Skip to content

image/gif: bounds offset reversed when encoding #30887

Closed

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?)

Activity

  1. katiehockman commented on Mar 19, 2019

    @katiehockman
    Contributor

    I was able to reproduce this, does seem that gif changes after the offset in a way that's different from the other image formats.

    /cc @nigeltao for image/gif package

  2. added
    NeedsDecisionFeedback is required from experts, contributors, and/or the community before a change can be made.
    on Mar 19, 2019
  3. added this to the Unplanned milestone on Mar 19, 2019
  4. gopherbot commented on Mar 21, 2019

    @gopherbot
    Contributor

    Change https://golang.org/cl/168418 mentions this issue: image/gif: don't assume Encode src's origin is (0, 0)

  5. splace commented on Mar 21, 2019

    @splace
    Author

    confirmed fixed. (with patch) demo now results in matching images and original code now works as expected. nice.

  6. added a commit that references this issue on Mar 21, 2019
    4dad64f
  7. locked and limited conversation to collaborators on Mar 20, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

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