pngpaste icon indicating copy to clipboard operation
pngpaste copied to clipboard

The color looks like not well when I used pngpaste in Mac Mojave

Open hjw6160602 opened this issue 5 years ago • 5 comments

The original picture is:

When I used pngpaste

hjw6160602 avatar Mar 22 '19 03:03 hjw6160602

I ran into the same issue, but not when I pngpaste directly. Also, only when I use .png. JPEG works fine.

How to reproduce

Faulty image:

  • Copy part of my screen with shift+ctrl+cmd+4
  • Paste into the program "skitch"
  • Copy the image in "skitch"
  • pngpaste arne.png

image

Ok image:

  • Copy part of my screen with shift+ctrl+cmd+4
  • pngpaste arne.png

image

Almost ok image:

  • Copy part of my screen with shift+ctrl+cmd+4
  • Paste into the program "skitch"
  • Copy the image in "skitch"
  • pngpaste arne.jpeg

image

maglub avatar May 06 '19 10:05 maglub

I have this problem, too. The pasted image looks greyed out.

NightMachinery avatar Oct 10 '20 13:10 NightMachinery

This happens very badly for fullscreen screenshots. Any ideas?

NightMachinery avatar Apr 03 '21 09:04 NightMachinery

Using these instead works fine:

function pngpaste() {
    local name="${1}"
    ensure-args name @MRET
    ensure isDarwin @MRET

    [[ "$name" =~ '\.png$' ]] || name+=.png

    osascript -e "tell application \"System Events\" to ¬
                  write (the clipboard as «class PNGf») to ¬
                          (make new file at folder \"$(pwd)\" with properties ¬
                                  {name:\"${name}\"})"
}
function jpgpaste() {
    local name="${1}"
    ensure-args name @MRET
    ensure isDarwin @MRET


    [[ "$name" =~ '\.jpg$' ]] || name+=.jpg

    osascript -e "tell application \"System Events\" to ¬
                  write (the clipboard as JPEG picture) to ¬
                          (make new file at folder \"$(pwd)\" with properties ¬
                                  {name:\"${name}\"})"
}

Usage:

pngpaste a1.png

NightMachinery avatar Apr 03 '21 09:04 NightMachinery

Yes, the color is wrong. I need this to work for png and jpg and I need the base64 output method to pipe it back to the clipboard as base64, so I cannot use @NightMachinary's solution.

martin-braun avatar Nov 08 '21 02:11 martin-braun

(Years later) Is this still an issue? :)

jcsalterego avatar Feb 08 '23 18:02 jcsalterego

@jcsalterego Yes it is. Could you please look into it? I would really appreciate it. :)

martin-braun avatar Feb 08 '23 21:02 martin-braun

@martin-braun are you still on Mojave?

jcsalterego avatar Feb 08 '23 21:02 jcsalterego

still/also

jcsalterego avatar Feb 08 '23 21:02 jcsalterego

@jcsalterego No, I'm on Monterey at the moment. The image isn't washed out anymore, but the colors are still not correct. For instance, I copied this image:

I then run pngpaste test.png and this is the result:

test

Notice how the contrast is too strong now?

Since you never touched the library and it turned around itself with the update of MacOS, I assume the original color issue was a bug in Apple's software, but is the wrong contrast at this time also Apple's fault?

martin-braun avatar Feb 08 '23 22:02 martin-braun

Interesting! Maybe there's a setting in the API that I could tweak so it doesn't mess with the contrast. Thanks for the test cases.

jcsalterego avatar Feb 08 '23 22:02 jcsalterego

@martin-braun I'm not seeing the same thing. Can you tell me how you copied the source file, and which pngpaste command you used for the output?

jcsalterego avatar Feb 09 '23 18:02 jcsalterego

@jcsalterego I copied the image via right click > copy image in Brave and I pasted with pngpaste test.png which I installed with brew install pngpaste.

Screen Shot 2023-02-10 at 3 38 46 PM

Screen Shot 2023-02-10 at 3 39 17 PM

macOS 12.6 (21G115)

Output:

test

martin-braun avatar Feb 10 '23 14:02 martin-braun

@martin-braun Got it - and can you reproduce the issue in Safari? I want to rule out the source copy being the problem.

jcsalterego avatar Feb 10 '23 14:02 jcsalterego

@jcsalterego You nailed it. On Safari the issue is not reproducible. I then tested to copy the image from Brave and paste it into another program, like Krita or Preview and the issue appears there as well, so it gets copied with the wrong contrast, thus it has to be a bug in Brave.

pngpaste works fine now, so this issue can be closed.

martin-braun avatar Feb 11 '23 16:02 martin-braun

@martin-braun Oh good, glad we tracked down the root issue.

jcsalterego avatar Feb 11 '23 16:02 jcsalterego

Hey @jcsalterego, I think this issue actually still exists. It seems to have to do with the Gamma metadata:

diff exif_orig.txt exif_pngpaste.txt
2c2
< File Name                       : orig.png
---
> File Name                       : pngpaste.png
5,7c5,7
< File Modification Date/Time     : 2024:05:08 09:56:11-04:00
< File Access Date/Time           : 2024:05:08 09:57:36-04:00
< File Inode Change Date/Time     : 2024:05:08 09:57:34-04:00
---
> File Modification Date/Time     : 2024:05:08 09:57:41-04:00
> File Access Date/Time           : 2024:05:08 09:57:42-04:00
> File Inode Change Date/Time     : 2024:05:08 09:57:41-04:00
19c19
< SRGB Rendering                  : Perceptual
---
> Gamma                           : 0.4545
20a21
> Color Space                     : sRGB

In certain viewers (like Windows Photo Viewer), the Gamma metadata is parsed and the image will appear faded.

rohitkapur avatar May 08 '24 14:05 rohitkapur