Add Text removes transparency?

Discussions on NConvert - the command line tool for image conversion and manipulation

Moderators: XnTriq, helmut, xnview

pcguy221
Posts: 3
Joined: Wed Jun 20, 2018 9:10 pm

Add Text removes transparency?

Post by pcguy221 »

Hello

Goal: Render watermark and text over a transparent png image.
Problem: Rendering text makes all transparency white.

If I just add the watermark (which is a png with transparency also), the transparency works.
If I just add the text, it renders text but converts all transparency to white.
If I add text and watermark (any order), text and watermark are shown but all transparency is converted to white.

Code: Select all

nconvert ^
-text_font arial 90 ^
-text_color 0 0 0 ^
-text_back 128 128 128 ^
-text_flag  center ^
-text_pos 111 111 ^
-text_rotation 0 ^
-text "test text outpuit 1" ^
-wmopacity 78 -wmflag bottom-left ^
-wmfile "C:\Users\Acct\watermark.png" ^
"C:\Users\Acct\transparent.png" 

PAUSE
Any ideas would be great! I have tried to fix this longer than I would like to acknowledge. I tried 5 pr 6 different PNG formats from photoshop using various export methods and settings. I also tried to fix the image in RIOT image optimizer. I also tried changing the order of commands. I also tried green gif and setting green as transparent before the rest and that didnt work either - although I prefer PNG with alpha anyway. I also tried maybe 20 variants of different transparency settings in nconvert.

** I wanted to add that these same source files and tasks do work in xnconvert, that do not work in nconvert. Even using the exported script. But I really wish for nconvert to be the tool.

Thanks in advance
cday
XnThusiast
Posts: 4185
Joined: Sun Apr 29, 2012 9:45 am
Location: Cheltenham, U.K.

Re: Add Text removes transparency?

Post by cday »

I don't have much experience with transparency, and XnTriq who is the expert doesn't normally post on NConvert issues and in any case hasn't been posting much recently, so while waiting for Pierre to respond, if he does, it might help if you could:

o Upload a simple test image transparency.png

o Upload a simple test watermark file watermark.png

o Reduce your code to the absolute minimum terms required to illustrate the problem, remembering that arguments will normally have default values, and you probably don't need to rotate the text, for example, to reproduce the issue. You to some extent also present the issue as two problems but writing text on the transparent source image is likely the real problem, isn't it?

In passing and probably not relevant, I notice that XnConvert has a text opacity value, and I don't see a way of setting that in the NConvert help file??

It does look like a possible NConvert bug, and reducing the issue to the minimum required to reproduce it could help motivate Pierre, or anyone else, to investigate it...
pcguy221
Posts: 3
Joined: Wed Jun 20, 2018 9:10 pm

Re: Add Text removes transparency?

Post by pcguy221 »

Thanks for the info! Heres some examples.

Watermark png with transparency
Image


Transparent 256px png
Image


Transparent 256px png with watermark only (transparency yes!)

Code: Select all

nconvert ^
-wmopacity 75 ^
-wmfile "C:\Users\Acct\w.png"   ^
"C:\Users\Acct\256.png" 
PAUSE
Image


Transparent 256px png with text rendered (transparency gone :()

Code: Select all

nconvert ^
-text_font arial 40 -text "Gobbleygook" ^
"C:\Users\Acct\256.png" 
PAUSE
Image


Transparent 256px png with watermark and text :(

Code: Select all

nconvert ^
-text_font arial 40 -text "Gobbleygook" -wmopacity 75 ^
-wmfile "C:\Users\Acct\w.png"   ^
"C:\Users\Acct\256.png" 
PAUSE
Image

*Host renamed the files a bit, but the top 2 are the test bg and watermark.

I'm hoping this is just some args I'm missing and not a bug. Thanks for any help in advance.
cday
XnThusiast
Posts: 4185
Joined: Sun Apr 29, 2012 9:45 am
Location: Cheltenham, U.K.

Re: Add Text removes transparency?

Post by cday »

Yes, confusing...

I've taken the liberty of editing your previous post slightly to add more space between the images you uploaded, so that the headings relate more clearly to the relevant image, I hope. Your 256px image above is also 180px, I believe.

I have done some tests of my own using your watermark and source transparency files: the results are confusing because I was unable to write text onto a transparent file, whether or not the watermark had been applied, and the image remained transparent rather than being changed to white.

After experimenting a bit, I reduced your problem to the following code, which uses my own file names:

Code: Select all

nconvert -wmopacity 75 -wmfile watermark.png -text_font arial 40 -text "Test" image.png
Doesn't the problem really reduce to the fact that you can't write text to an image that is transparent, or at least not to the transparent image that you uploaded?

NConvert does not write text to a transparent image although I can confirm that XnConvert does...

I'm attaching my test files.
Test_files.zip
You do not have the required permissions to view the files attached to this post.
pcguy221
Posts: 3
Joined: Wed Jun 20, 2018 9:10 pm

Re: Add Text removes transparency?

Post by pcguy221 »

Thanks for the edit and upload. This is funny a little. I used the files you provided and this time the words were partially written over top the watermark. Not on the fully trapsparent pixels, but only where the watermark and its shadow were.
Image

Strange how the text doesn't provide its own (pixel to pixel opaque & transparent ) backing adjusted only by text transparency. Im not sure if this is a bug or a known limitation. And like you, XNconvert handles fully transparent starting files perfectly in my experience.

So heres some red backgrounds. 25% transparent is good. And text DOES write to it with the watermark and without. But its transparency matches the background. And it changes the transparency of the watermark.
Image Image

So the same problem still but a bit different. I can write to a semi-transparent background, but its matching transparency make it unusable. I tried to write text over the faint result image, hoping the darkness of the text would build up after 4 layers to 100% but it didn't.

...Can XNconvert be run in command line?
...Is it possible to generate some sort of negative mask of the text where transparency is only at the rasterized text for a perfect fit? And then use that overtop any solid color opaque background to make your own transparent images. Impractical compared to the ease of this task in xnconvert, but is that what it would take? XNconverts text is might clean looking and nothing like the color keyed text I have seen also.
...can I make a opaque 1 color image transparent in nconvert and write to that result? What if the text has a opaque backing then. I don't know the code for that. Im not really sure where to go from here without getting too far from the manual.

Thanks
cday
XnThusiast
Posts: 4185
Joined: Sun Apr 29, 2012 9:45 am
Location: Cheltenham, U.K.

Re: Add Text removes transparency?

Post by cday »

pcguy221 wrote: Fri Jun 22, 2018 2:37 amCan XnConvert be run in command line?
I don't think so, at least not the way you need.

This continues to be very confusing, with your results using the same source files in some respects seeming different to my results.

I think the way forward is to keep the issue as simple as possible:

XnConvert produces the expected result, NConvert does not...

I suggest you post new image and watermark test files, with those names, and in a ZIP to ensure that they cannot possibly be modified in any way when uploaded, together with your XnConvert result and your minimal NConvert code. Then Pierre should be able to easily reproduce the issue and investigate any confirmed bug.

Edit:

If the issue can in fact be reproduced with just a transparent source image, without applying the watermark, you may as well reduce the issue to that and post just what is needed...

Edit 2:

I have confirmed that NConvert does NOT write text to the above transparent image.png, no need to add a watermark, whereas XnConvert does.

I have been trying to prepare a new post but my attachments uploaded to the forum keep vanishing from the draft for an unexplained reason. :(
User avatar
xnview
Author of XnView
Posts: 44917
Joined: Mon Oct 13, 2003 7:31 am
Location: France

Re: Add Text removes transparency?

Post by xnview »

i contact you by PM
Pierre.