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

Feature: download selection as PNG #36

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

ldiqual
Copy link

@ldiqual ldiqual commented Sep 9, 2012

I needed this feature to split a sprite into multiple images. This commit adds a new button "Save selection" which allows to download the current sprite selection.

It relies on canvas2image and a new class spritecow.RectSaver.

@jakearchibald
Copy link
Owner

This look really cool, nicely worked into the slightly inadequate build scripts too. Will give this a spin on the train home & merge it in. We'll be able to refactor most of canvas2image away, since it's only using a very small part of it.

@jakearchibald
Copy link
Owner

I've pulled this into a branch to hack on it - https://github.com/jakearchibald/sprite-cow/tree/feature/save-selection

I'd like to look into ways to give it a proper file extension when it saves, the download attribute may help with this http://www.whatwg.org/specs/web-apps/current-work/multipage/links.html#attr-hyperlink-download

@ldiqual
Copy link
Author

ldiqual commented Sep 12, 2012

Thanks Jake.
I already thought about it, and I think we'll have some troubles. The download attribute is for a elements only, so we'll have to generate the canvas before the user clicks on the link. This means create a canvas, copy the selection on it, extract data, put it in the href attribute, everytime the user selects something.

Plus, I think the href data length is limited under some browsers.

I'll take a look at other image-saving implementations, it might help.

@jakearchibald
Copy link
Owner

http://jsbin.com/ulobic/1/ - changing a link href on mousedown seems to work, 'click' may work too & be safer for different input types.

Are there browsers that have a shorter a.href limit than location.href? The MDN page just suggests a hard limit on data uris.

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

2 participants