Page 1 of 1

Transparency for

Posted: Mon Sep 16, 2024 8:29 pm
by Micharius
Hello everybody

We need to convert big scanned plans. They are all TIF and scanned in black & white.

However, we need them with transparent background and Nconvert would be ideal to run from a command line to set the color white to transparent.

Its a piece of cake with XnConvert (see screenshot), but despite searching and trying, I wasn't able to get the same result as in XnConvert with NConvert: Simply replace with (255 255 255) with transparent color.

Does anybody know how to do this?

Also, I can't get the Reference Manual linked on https://www.xnview.com/wiki/index.php?t ... User_Guide , the file seems to be corrupted.

Does anybody have it?

$any thanks for your help in advance,

Micharius
(non-Englisch speaker...)

Re: Transparency for

Posted: Mon Sep 16, 2024 9:05 pm
by cday
I think it would be helpful if you could:

o Create a small test file with similar properties to the files that you wish to convert, the same bit depth (1, 8, 24 or 32 bits) and compression option, etc., that converts in XnConvert but not using your NConvert code.

o Post the XnConvert output file;

o Post the NConvert code that you are using.

Maybe you could crop out a small area of one of your files, or you could, for example, create a suitable file using the XnView MP File > New image... and Image > Draw... options.

Note that I am not very knowledgeable about transparency, but defining the issue fully may assist Pierre, or maybe even someone else!

As you say, the link to the NConvert PDF guide is broken, but I don't think it contained any additional text to that in the HTML file.

Re: Transparency for

Posted: Wed Sep 18, 2024 6:43 am
by Micharius
Hello
Thanks for offering your help.
Attached is one of the scanned plans. I had to compress it, the raw file was too big.

What I tried with nconvert

Code: Select all

nconvert -transpcolor 255 255 255 -out tiff -o output.tif test_white_1.tif
** NCONVERT v7.192 (c) 1991-2024 Pierre-E Gougelet (Aug 26 2024/11:00:16) **
        Version for Windows 7/8/10/11 x64  (All rights reserved)
** This is freeware software (for non-commercial use)

?==> 0
Conversion of test_white_1.tif into output.tif OK
This indeed gives me a file output.tif, but it's almos 31x the size of the original file, and without transparency.

Re: Transparency for

Posted: Wed Sep 18, 2024 7:37 am
by cday
These are the properties of your attached test image:

test_white_1.tif_Properties.png

Could you please post the properties of the original full-size image using XnView MP Image > Properties...

I am concerned that your smaller test image may have different properties.

You might be better making a crop of a small area of a full size image, and then ensuring that it is saved with identical properties to the original image.

You should also please ensure that your test image converts to transparent using XnConvert so that the test image is valid.

Note: I don't have much time today.

Re: Transparency for

Posted: Wed Sep 18, 2024 10:12 am
by user0
you messed your BW file while editing/saving, fixed one:
test_white_1_bw_CCITT G4.zip
(509.73 KiB) Downloaded 124 times
also check TIFF's compression settings to reduce file size

you cannot have transparency in 1bit monochrome image, so you need to convert it into:
- indexed (PNG) OR
- 32bit (TIFF, PNG)

Re: Transparency for

Posted: Wed Sep 18, 2024 10:29 am
by cday
Thank you user0, I said that I had limited knowledge of transparency, unfortunately very few members ever post on NConvert topics... :wink:

Black and White 1-bit TIFFs with CCITT G4 [Fax] compression would certainly be the best [readily available] way to archive those drawings, but if transparency is required for their use that can be expected to increase their file size. If there is a large collection of drawing, possibly they could only be converted to transparent images when used.

@Micharius:

If confidentiality is not an issue and an original file is not too large, maybe you could provide a download link to an example file to remove any uncertainty?

Re: Transparency for

Posted: Mon Sep 23, 2024 12:45 pm
by XnTriq
  1. Download and extract the sample provided by Micharius.
  2. Open test_white_1.tif in XnView Classic.
  3. Go to ImageConvert to BinaryBinary (No Dither).
  4. Go to ImageConvert to Colours… and select 8 colors without dithering.
  5. Go to ImageEdit Palette… and Enable transparency for white.
  6. Save the file as test_white_1.png.
    Result: 4-bit indexed with a 16-color palette and alpha channel transparency (1'006'671 bytes)
  7. Optimize test_white_1.png with PngOptimizer (lossless).
    Result: 1-bit grayscale with transparency (722'184 bytes)

Re: Transparency for

Posted: Wed Oct 16, 2024 6:29 pm
by user0
hm.. tinypng.com reduces 4bit with transparent index from 1Mb to 673kb
which can be resaved in xnviewmp as 32bit avif (523kb, 15mins) or webp (776kb, 2mins)
after_tinypng.png

Re: Transparency for

Posted: Thu Oct 17, 2024 12:00 am
by XnTriq
user0 wrote: Wed Oct 16, 2024 6:29 pmhm.. tinypng.com reduces 4bit with transparent index from 1Mb to 673kb
Wow, confirmed :-?
And it's lossless.

IHDR: 1 bit/sample, grayscale, noninterlaced<br />tRNS: transparent color = (1)<br />722'184 bytes
IHDR: 1 bit/sample, grayscale, noninterlaced
tRNS: transparent color = (1)
722'184 bytes
IHDR: 1 bit/pixel, paletted, noninterlaced<br />PLTE: palette, 2 entries<br />tRNS: alpha values for palette color, 1 entry<br />673'072 bytes
IHDR: 1 bit/pixel, paletted, noninterlaced
PLTE: palette, 2 entries
tRNS: alpha values for palette color, 1 entry
673'072 bytes