Search code examples
gnuplottransparencypixmap

gnuplot: How to display transparent png with pixmap


I am trying to place images (png) on top of a map using the set pixmap command.

pixmap displayed on Map

It does work but the transparency of the png is not getting "displayed", and I get a white background instead.

Can the pixmap feature handle the transparency property of an image?

Here is the script:

$DATA<<EOD
1,"Washington",630.2000,1591.1800
EOD
$DATA01<<EOD
1 "C:\\Temp\\Images\\colors.png" 630.2000 1591.1800
EOD
set datafile separator comma
set style data point
set term windows enhanced size 3000.00,2000.00
unset xtics; unset ytics; unset x2tics; unset y2tics
set grid noxtics
set grid noytics
set border 0
set colorsequence classic
set key off
set for [i=1:1] pixmap i word($DATA01[i], 2) center at word($DATA01[i], 3), word($DATA01[i], 4) width 100 height 100 
plot 'C:\Magic\XPA\46s\Add_On\ChartGenerator\Geography\USA_Curved_Names_Blue.png.jpg' binary filetype=JPG w rgbimage,\
$DATA every ::0::0 using ($3):($4) notitle,\
$DATA using ($3):($4):($2) with labels font "Tahoma,20" textcolor rgb "purple" center offset 0,1 notitle

here is the png file: sample png file

and the map file: enter image description here

Roberto


Solution

  • I do not know what is going on here exactly, but it has something to do with the image file itself. If I open that file in GIMP and export it to a new file with no intervening edit/modify operations, then the exported file works correctly as a pixmap with transparent areas.

    Comparing the output of identify -verbose original.png and identify -verbose redo.png doesn't show anything that stands out to me except possibly the png:IHDR.color_type entries.

    I attach the re-exported file here - try it in place of your original image file and see if that works. enter image description here

    For what it's worth, here is the diff between identify run on the two files:

    diff -urp original.identify redo.identify 
    --- original.identify   2023-10-25 22:38:42.002322272 -0700
    +++ redo.identify       2023-10-25 22:38:57.165582322 -0700
    @@ -1,5 +1,5 @@
     Image:
    -  Filename: original.png
    +  Filename: redo.png
       Permissions: rw-r--r--
       Format: PNG (Portable Network Graphics)
       Mime type: image/png
    @@ -703,25 +703,26 @@ Image:
       Compression: Zip
       Orientation: Undefined
       Properties:
    -    date:create: 2023-10-26T02:58:38+00:00
    -    date:modify: 2023-10-26T02:58:34+00:00
    -    date:timestamp: 2023-10-26T06:23:13+00:00
    +    date:create: 2023-10-26T06:22:24+00:00
    +    date:modify: 2023-10-26T06:22:24+00:00
    +    date:timestamp: 2023-10-26T06:23:23+00:00
    +    png:bKGD: chunk was found (see Background color, above)
         png:IHDR.bit-depth-orig: 8
         png:IHDR.bit_depth: 8
    -    png:IHDR.color-type-orig: 2
    -    png:IHDR.color_type: 2 (Truecolor)
    +    png:IHDR.color-type-orig: 6
    +    png:IHDR.color_type: 6 (RGBA)
         png:IHDR.interlace_method: 0 (Not interlaced)
         png:IHDR.width,height: 512, 512
         png:pHYs: x_res=3780, y_res=3780, units=1
    -    png:tRNS: chunk was found
    +    png:tIME: 2023-10-26T06:22:24Z
         signature: cb4667f54b948708bd7fd893e4668ca843bf816392a4bad8c8917b967cf1f1ea
       Artifacts:
         verbose: true
       Tainted: False
    -  Filesize: 11772B
    +  Filesize: 11446B
       Number pixels: 262144
       Pixel cache type: Memory
    -  Pixels per second: 21.2189MP
    +  Pixels per second: 21.0638MP
       User time: 0.010u
       Elapsed time: 0:01.012
       Version: ImageMagick 7.1.1-11 Q16-HDRI x86_64 21206 https://imagemagick.org
    

    If you spot anything relevant there, let me know. If it's a reproducible file property that can be tested for, maybe gnuplot can be taught to fix it or at least emit a warning.