Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

imsave should preserve alpha channel #1956

Merged
merged 1 commit into from May 3, 2013

Conversation

Westacular
Copy link
Contributor

While looking at test_image, I noticed the comment that imsave was flattening alpha channel data. I figured this was related to #1868 (it is, partially), and decided to fix it.

I've updated the test to reflect that an imsave/imread round-trip should now preserve full RGBA data to within 1/255.

Passing the test, however, requires that the patches from #1868 also be applied.

@@ -1273,7 +1273,8 @@ def imsave(fname, arr, vmin=None, vmax=None, cmap=None, format=None,
fig = Figure(figsize=figsize, dpi=dpi, frameon=False)
canvas = FigureCanvas(fig)
im = fig.figimage(arr, cmap=cmap, vmin=vmin, vmax=vmax, origin=origin)
fig.savefig(fname, dpi=dpi, format=format)
fig.patch.set_alpha(0)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does the transparent kwarg on savefig do the same thing? (http://matplotlib.org/faq/howto_faq.html#save-transparent-figures)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You're right, it does. (Silly me, I'd forgotten about that option.)

I've updated the branch to use that instead.

@pelson
Copy link
Member

pelson commented May 1, 2013

Ah. Unfortunately the travis-ci instance has this test failing: https://s3.amazonaws.com/archive.travis-ci.org/jobs/6792238/log.txt
Surprisingly the numbers are quite different.

@Westacular
Copy link
Contributor Author

That's because #1868 hasn't been merged. (This hits the same problem that that fixes.) On my test branch with both patches applied, the test passes.

@pelson
Copy link
Member

pelson commented May 1, 2013

That's because #1868 hasn't been merged.

Doh! Time to go home - its been a long day 😄

@Westacular
Copy link
Contributor Author

Oh, oops. I think I half-botched a rebase of this branch, but the overall diff is still correct.

@pelson
Copy link
Member

pelson commented May 3, 2013

Oh, oops. I think I half-botched a rebase of this branch, but the overall diff is still correct.

I think we only need a single commit for this change, so would you mind going ahead and squashing your changes? if its more trouble than its worth, don't worry about it though.

@Westacular
Copy link
Contributor Author

I think we only need a single commit for this change, so would you mind going ahead and squashing your changes?

Done (and managed to do it right this time.)

@mdboom
Copy link
Member

mdboom commented May 3, 2013

👍 -- @pelson: I leave it to you to push the green button since you've been following all this closer than I.

pelson added a commit that referenced this pull request May 3, 2013
Imsave now preserves the alpha channel.
@pelson pelson merged commit b6b9062 into matplotlib:master May 3, 2013
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.

None yet

3 participants