jcsalterego / pngpaste

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

Format agnostic tool? #8

Closed igr closed 7 years ago

igr commented 7 years ago

Would it be possible to make it format agnostic? e.g. to detect JPG and store as JPG... I would not like to clone just to make a jpg version of it; would it be cool to have it all in one. wdyt?

jcsalterego commented 7 years ago

Sounds like a good idea, though I'd have to think of the right CLI interface, since right now it's pngpaste thefile.png, so perhaps pngpaste --auto-detect-extension thefile or pngpaste -a thefile? Either way, I can try to incorporate any format detection code this week if you have any contributions there.

igr commented 7 years ago

You might even skip autodetection for now - just use the target extension, i.e.:

pngpaste foo.png       // will copy PNG
pngpaste bar.jpg       // will copy JPEG

I am not osx dev, but looking the code, can you simply replace png with jpeg and make it work ;)))?

jcsalterego commented 7 years ago

Yeah true, that's much simpler, though would pngpaste be responsible for performing a conversion?

I'll take a look this week and update this issue.

igr commented 7 years ago

Thank you! what conversion? you mean from png to jpg, or? Would it be possible that when I copy a jpg file (like from webpage), simply store that content in a file, without any conversion?

jcsalterego commented 7 years ago

what conversion? you mean from png to jpg, or? Would it be possible that when I copy a jpg file (like from webpage), simply store that content in a file, without any conversion?

Yeah, I mean if the user has copied a JPEG, but tries pngpaste some.png, or the user has copied a PNG, but tries pngpaste some.jpg.

igr commented 7 years ago

Got it. Well, for the first version you can just throw an error; if conversion is too much work :)

I would not expect from your tool to do conversion, that might be out of scope, and conversions may be complex. I would rather work on autodetection so when you don't specify the extension:

pngpaste foo

it will detect the right pic format and store it in eg foo.jpg or foo.png or foo.tiff :)

jcsalterego commented 7 years ago

So unfortunately I dug into it and AppKit's API doesn't expose the original source's format. It just comes back as a "bitmap" and there's no clear enum or string that indicates whether the source was a JPEG, a PNG, a GIF, etc.

Thus, #9 does allow for pngpaste foo.jpg but there's no auto-detection of the actual source. This is the data structure provided - https://developer.apple.com/reference/appkit/nsbitmapformat?language=objc - and it is not quite helpful in the detection endeavor.

jcsalterego commented 7 years ago

Going ahead and closing this.