Testing a posting method, with a Pretty Floppy
OKAY so if I copy-paste out of my image editor, like this, I get a PNG.
(better than a BMP, at least, and it makes sense for screenshots)
but if I copy a jpeg file in explorer, it pastes as a jpeg.
so here's my idea: I write a little script that yanks the PNG out of the clipboard, saves it as a JPEG to a temp folder, then copies that jpeg file. So instead of directly posting out of my image editor, I do copy, click the script icon, then paste.
that'd be only a minor change to my workflow, it'd fix the PNG problem, and it wouldn't be too hard to write, I don't think.
basically I'm trying to avoid the problem of posting giant PNGs when they'd be better served as a small JPEG. Twitter doesn't care what you post, it will JPEG them if it feels like it, and I have been unintentionally depending on that functionality
basically my workflow is this:
I take a bunch of pictures with my phone, then they get autosynced to my desktop.
on the desktop, I go into my camera folder and drag them all into my image editor. I rotate them as needed, then select the rectangle I want to post, and copy it. I then paste it into twitter/mastodon/whatever.
this technically still works on mastodon, but results in giant PNGs being uploaded, which load slowly and waste space on the server.
OKAY so if I copy a region in paint.net and then run my enumerate-clipboard-formats command, I get the following formats.
CF_DIBV5 is the recommended bitmap format, but there's a custom "PNG" format in there too. Maybe I can just grab that and throw it at imagemagick?
For comparison, after I copy a file from windows explorer:
I wonder what formats my browser will accept?
because in theory maybe I could give it just a CF_DIBV5 and JPEG-encode it.
a quick check of firefox and chrome source code, it looks like firefox goes for CF_DIBV5 and chrome goes for CF_PNG and CF_DIBV5
no idea if they'll accept a jpeg'd CF_DIBV5. I'm not certain I want to expend the effort to find out
But if I grab the data out of that C154 format, it's indeed a fully valid PNG file. Cool.
testing
it works!
and it's now on my github:
https://github.com/foone/pastejpeg
GitHub - foone/pastejpeg: Converts a PNG on the windows clipboard into a JPEG you can paste

Converts a PNG on the windows clipboard into a JPEG you can paste - foone/pastejpeg

GitHub
quick test again
There. Now I've got a little button on my task bar that runs it.
I'll stick a guide on how to set that up in the README when I get a chance.
@foone If I still had any doubt that you may not be the real Foone, this thread removed them.
@foone "pastej" in Swedish means approximately pâté, and... I'm not sure what to say about "pastej peg".

@foone
Oh yeah, I love GreenShot

I used to use Purrint for the longest time, but Win10 adds these huge margins around the windows. GreenShot gets proper pictures. Also scripting!

So I guess you're using Greenshot to grab the screenshot, and then it runs your pastejpeg program passing a path the the saved screenshot PNG to it? Then your pastejpeg probably replaces what's in the clipboard.

@foone this is really cool! I might have to adapt this as a script that stays running on the system tray and always checks when the clipboard changes for PNGs 👀
@foone Qt applications using QClipboard – or at least nomacs – also seem to provide their own PNG data. Even though I could pull out 0xc175 or 0xc176 directly here.

@foone Fun. After reading the first toots I was already wondering whether something like this would work on #X11 without much code. It actually does in a hackish way:

1. When the clipboard contains image/png data, fetch it with xclip
2. Use convert to get a JPG (or create lossy WebP or whatever)
3. Read that with xclip -t image/png
4. Paste it.

At least Firefox will get an image/png that is actually a JPEG data, the Mastodon client will send it as image/png and the server will interpret it as image/jpeg … xclip -t image/jpeg does not work and Chrome doesn't accept the invalid PNG, though.

@foone That's cunning. Would be great to have similar for converting formatted text to plaintext -- nobody ever wanted to paste text with its formatting.
@foone wouldn't it be easier to create a web browser script for this ?
@foone Did it poop on the windshield? If so the test was a failure.
@foone Came through fine! Here's a screenshot from my end:
@foone for some reason Tusky won't render that inline for me, just show it as an attachment, I wonder if that's a problem on my instance I need to go fix
@foone I do hope this isn't the start of a particularly gruesome teardown thread...
@foone I thought this was gay cats at first and was about to ask for my money back.
@foone this isn’t the birdsite…
@foone Ole Private Data is the title of my ST:TNG / Gomer Pyle fanfic

@foone
#!/bin/bash
for file in images_small/*.png; do
convert $file -resize 400x200 $file
done

I'm sure you can make a windows equivalent. On my mac, I have tied an image-editing script to Finder via Keyboard Maestro, so I can click a file to automate the processing.

@cattailnu the problem is that there are no files. it's in the clipboard.
@foone You could use a partial-screen capturing software instead of copying to clipboard. I have one that dumps to a file on the desktop.
@foone if you're going to make workflow chances, why not paste as webp? Or maybe Mastodon/apps don't support it?
Support WebP images · Issue #13315 · mastodon/mastodon

Pitch I just downloaded a .webp image from a website and was surprised when I wasn't able to share it in a Mastodon post. Motivation I think this should be possible, because most users would ex...

GitHub

@foone doesn't PNG support similar compression like JPEG does? Maybe it just needs to be tickled that way / resized?

Asking since I *think* PNG is supposed to be a newer and better format, but I very well may be mistaken.

@viq @foone png is lossless, so you will get better quality, but usually much larger files.
@katrinatransfem @foone Oh, indeed, I thought PNG is / can be lossy as well, I stand corrected. Thank you :)
@viq @foone Basically, PNG likes big areas with flat colors, which it compresses well. It's great for icons and screenshots of text, which it preserves with pixel perfect accuracy, but it's terrible for photos. It doesn't lose any data, it just creates huge files. PNG is more like a better GIF (sans animation) than JPEG.

@viq no, the compression is completely different, both in effect and idea

The compression in PNG is lossless, like a ZIP (in fact, it uses the same compression algorithm as ZIP files, DEFLATE). You always get the same pixels out that you put in. Downside: you generally can't compress *too* much, and it doesn't really work for photographs, because even you have a picture of a white wall, it's not all the exact same white everywhere, unlike in digital drawings

@viq JPEG, on the other hand, is lossy. By creating a JPEG, you lose information you can't get back

The compression is complex-ish, based on the direct cosine transform, which works similar to a fourier transform, i.e. it analyzes the frequency components and then throws away subtle changes in the pixels you're not likely to notice

Work great for photos, because, like I said, in the natural world, white isn't pure #000000

@viq But doesn't work well for anything with hard edges like digital drawings, comics, text, and also screenshot. You get "artifacts" around those, ringing. You might have seen those on badly compressed JPEGs of screenshots with text

For something here on social media, foone doesn't seem to care that much to get 100% pristine images, tho

And depending on the quality setting, how much it's compressed and how much you look for it, it might not be that noticable

@viq so it's not necessarily important that PNG is newer than JPEG, it's more that they solve different problems. They target different use cases

Roughly:

- JPEGs are for photos of the real world, with its impressions

- PNGs are for digital drawings, where you have hard edges, areas of exactly the same color, that sort of thing. Where it's important that what you put it is what you get out again

@viq discrete cosine transform*, narf
@foone isn’t that something that should really be fixed on the server? Mastodon already has transcoding support for building previews and such (and someone was claiming it strips some EXIF), should be a doable patch to convert at time?
@matt probably!
but I want it fixed today.
@matt @foone agree, it feels like something the service should care about. Image management is definitely a thing I'd like to have better control over as an instance owner
@foone but it means your followers can actually read labels, lettering and captions in the image. And in the case of your images, we can see the details in the hardware you're on about this week.
[Jpg distortion sucks]
@scotchfairy the images I'm pasting are already JPEG, that's what they came out of the camera as. I'm not really losing any quality here, I'm just avoiding making the size huge.