Why do pasted png get converted to jpg

AI-generated summary

The discussion revolves around a Discourse commit that converts pasted PNG images to JPG. spirobel asked about the reason behind this conversion, citing the commit. codinghorror initially provided a link to a blog post about screenshot formats, but spirobel clarified that their question was specifically about pasted PNGs.

codinghorror explained that pasted images are typically raw bitmaps, and saving them as PNG (lossless) would result in large file sizes. Instead, the system tests saving in both formats and chooses the one with a “reasonable” size, often resulting in JPG (lossy) for efficient storage.

spirobel thanked codinghorror for the explanation and asked follow-up questions about reproducing the issue and the meaning of “raw bitmap.” They later edited their post to clarify that they had misunderstood the term “pasted” and were actually using drag-and-drop, as copy-pasting images did not work on their system.

https://github.com/discourse/discourse/commit/a9c0df0b58c5495c574286084278b00a5d283cd3
Hi,
I wanted to ask about this commit. Why do pasted PNGs get converted to JPG in any case? what breaks without this commit? why is it called FIX?
Thank you very much :smiley:
spirobel

See Screenshots: JPEG vs. GIF (and PNG)

I am sorry, but I can not find the answer to my question in your link. My question is not why pngs get converted to jpg, my question is: why do pasted PNGs get converted to JPGs? I dont understand why there is a difference between pasted and non pasted.
Thanks :smiley:

Pasted images typically come across as raw bitmaps, so saving them all as PNG (lossless) would be hugely wasteful in file size. Instead we test saving in both formats and see which results in a “reasonable” size, so (most) images end up efficiently stored as JPGs (lossy).

Thank you for your answer! I think I start to understand this now.

-----------------------------149589358933568048074206291858

Content-Disposition: form-data; name="type"

composer

-----------------------------149589358933568048074206291858

Content-Disposition: form-data; name="files[]"; filename="Screenshot_2020-05-05.png"

Content-Type: image/png

How can I reproduce this? I used the inspector and looked at the request and saw this when pasting a png, when I tried with a jpg it will say image/jpg. What does raw bitmap mean? With which browser does this happen (I use firefox)?

EDIT okay never mind, I think maybe I misunderstood what pasted means. I actually did drag and drop. I tried to copy and paste an image, but it seems like it does not work in general on my system. It just adds this text to the the composer:

x-special/nautilus-clipboard
copy
file:///home/username/Downloads/Screenshot_2020-05-05%20.png