|P is for Practical|
Really? IMHO png and jpg use compression methods resulting in unpredictable information loss. IMHO converting them to a raw format will not often produce identical data.
Really. And to resolve your doubts please try it.
The "secret" such as it is, is that the raw format used for the comparison is neither jpg nor png, but libgd's own internal format, which is an uncompressed, lossless format. The images of all formats supported by GD are
By way of demonstration, in my post above, I took a jpg image of a mandrill monkey and used an image editor to convert it to a compressed but lossless .png. I then compared those two images and no discrepancies were found.
By way of further demonstration, using the slightly expanded version below, I then edited the ,png version by changing the color of a single pixel on the mandrill's nose, from it's original near white color to pure red. and then compared that against the original .jpg:
As you can see, that single pixel difference was correctly detected by the raw binary compare, and then subsequently isolated using a pixel-by-pixel comparison. Please try it to convince yourself that it is correct.
But do bear in mind my warning above. If, for example, you were to take a ,png image and convert it to a lossy image format such as .jpg, then although the images may appear superficially similar to the human eye, they may be quite different in actuality. This due to the jpeg algorithms practice of substituting a single color for many, closely aligned but mathematically different colors in order to reduce palette sizes and aid compression.
Such lossy transforms will be correctly detected as different, even though cursory, by-eye inspections might adjudge them to be the same.
The expanded code:
Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
"Science is about questioning the status quo. Questioning authority".
In the absence of evidence, opinion is indistinguishable from prejudice.