Skip to content

Start copying at bounds min instead of zero point#38

Merged
fogleman merged 1 commit into
fogleman:masterfrom
tschaub:subimage
Mar 16, 2018
Merged

Start copying at bounds min instead of zero point#38
fogleman merged 1 commit into
fogleman:masterfrom
tschaub:subimage

Conversation

@tschaub
Copy link
Copy Markdown
Contributor

@tschaub tschaub commented Mar 16, 2018

This makes it possible to create a context from an image that is returned by other.SubImage(rect).

Here is a case that demonstrates the problem with the current imageToRGBA func (no error handling for brevity):

package main

import (
	"image"
	"image/png"
	"os"

	"github.com/fogleman/gg"
)

func main() {
	file, _ := os.Open("tile.png")
	im, _ := png.Decode(file)

	rgba := im.(*image.RGBA)

	cropped := rgba.SubImage(image.Rect(30, 40, 246, 246))

	file, _ = os.Create("cropped.png")
	png.Encode(file, cropped)

	file, _ = os.Create("gg.png")
	png.Encode(file, gg.NewContextForImage(cropped).Image())
}

With this tile.png:

tile

This is the cropped.png (expected):

cropped

And this is the gg.png (unexpected):

gg

Here is a repo that demonstrates the issue: https://github.com/tschaub/test-gg

@fogleman fogleman merged commit a9ff18e into fogleman:master Mar 16, 2018
@fogleman
Copy link
Copy Markdown
Owner

Thanks!

@tschaub tschaub deleted the subimage branch March 16, 2018 14:22
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants