jcsalterego / pngpaste

Paste PNG into files, much like pbpaste does for text.
Other
477 stars 32 forks source link

add output to stdout as base64 #19

Closed stef-levesque closed 4 years ago

stef-levesque commented 4 years ago

Allows to output the png as a base64 encoded string. Flag: -b

jcsalterego commented 4 years ago

This is a cool feature. I haven't tested it yet but could you:

Thanks!

stef-levesque commented 4 years ago

done

jcsalterego commented 4 years ago

Thanks for the quick formatting fixes.

How have you been testing this? Building an image/data chunk and looking in a browser?

Is there an existing base64 encoder we can use in Foundation?

https://developer.apple.com/documentation/foundation/nsdata/1413546-base64encodedstringwithoptions?language=objc

One thing I want to avoid is any sort of buffer overflow code in this simple utility.

stef-levesque commented 4 years ago

I've been testing it by pasting the content into a Markdown and previewing it. Markdown can include image in base64. Ex.

![smallpng](data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAUAAAAFCAIAAAACDbGyAAAALklEQVQI12P4//9/t+0rOMmAzOm2fcX4//9/BiTA0mP3moGBoeSQKITBBOHASQD5UyG73x3N2gAAAABJRU5ErkJggg==)

I can have a look at that API you linked. Is a requirement of macOS 10.9+ going to be an issue ?

jcsalterego commented 4 years ago

I can have a look at that API you linked. Is a requirement of macOS 10.9+ going to be an issue ?

Looks like MacOS 10.9 was released in 2013, so that's fine, I think. The link was just one example - I'm not sure what is the best way.

stef-levesque commented 4 years ago

You proposal is way less intrusive 😄

jcsalterego commented 4 years ago

Oh great, that looks much cleaner!

Do you intend for base64 to only be supported for stdout? What if I tried pngpaste -b test.png?

stef-levesque commented 4 years ago

It will behave the same as pngpaste - test.png, the file output is just ignored. It wouldn't make sense to output to a .png anyway, as this is a text string of base64 characters.

How I use it, mostly, is by :

jcsalterego commented 4 years ago

Yes, pbpaste -b test.png wouldn't make much sense - perhaps pbpaste -b test.png.b64 or something. Either way, makes sense to me. Thanks for your PR!

stef-levesque commented 4 years ago

Thanks!

jcsalterego commented 4 years ago

Now available in 0.2.3! :tada: https://github.com/jcsalterego/pngpaste/releases/tag/0.2.3