Transparent Background for Images with Text

Questions and postings pertaining to the usage of ImageMagick regardless of the interface. This includes the command-line utilities, as well as the C and C++ APIs. Usage questions are like "How do I use ImageMagick to create drop shadows?".
Post Reply
joshiishan
Posts: 6
Joined: 2018-05-10T08:00:26-07:00
Authentication code: 1152

Transparent Background for Images with Text

Post by joshiishan » 2019-02-12T22:57:55-07:00

I have thousands of images with equations and text with white background. I need to make the white background transparent.

The command I tried as always was:

Code: Select all

convert _VP_EQN_61.GIF.png -fuzz 10% -transparent white _VP_EQN_61-converted.png
This command works perfectly with images without any text but when it comes to images with text, the edges/borders of the text becomes, for the lack of a word, unclear.
Example:
Original Image: Image
Result Image: Image

P.S. Please open the image in new tab with any dark background to see the issue clearly. Apologies for not being able to do it here.

I need some help creating images with transparent background with losing the text clarity/quality.

User avatar
fmw42
Posts: 24770
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Transparent Background for Images with Text

Post by fmw42 » 2019-02-13T01:00:12-07:00

try

Code: Select all

convert VP-EQN-61-GIF.png -negate -threshold 0 -negate -alpha copy -channel a -negate +channel result.png

snibgo
Posts: 11474
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: Transparent Background for Images with Text

Post by snibgo » 2019-02-13T05:29:40-07:00

An alternative method results in black text and anti-aliased alpha:

Code: Select all

convert VP-EQN-61-GIF.png -negate -alpha copy -channel RGB -evaluate set 0 +channel out.png
snibgo's IM pages: im.snibgo.com

joshiishan
Posts: 6
Joined: 2018-05-10T08:00:26-07:00
Authentication code: 1152

Re: Transparent Background for Images with Text

Post by joshiishan » 2019-02-14T01:03:01-07:00

fmw42 wrote:
2019-02-13T01:00:12-07:00
try

Code: Select all

convert VP-EQN-61-GIF.png -negate -threshold 0 -negate -alpha copy -channel a -negate +channel result.png
Thanks for your response. It gave me an image with thicker text (like bold) but the text border was not smooth. Attaching the resulting image.
Image.

It is looking good or fonts which are a bit thicker but not on the thin fonts.

Regards,
Ishan

joshiishan
Posts: 6
Joined: 2018-05-10T08:00:26-07:00
Authentication code: 1152

Re: Transparent Background for Images with Text

Post by joshiishan » 2019-02-14T01:05:13-07:00

snibgo wrote:
2019-02-13T05:29:40-07:00
An alternative method results in black text and anti-aliased alpha:

Code: Select all

convert VP-EQN-61-GIF.png -negate -alpha copy -channel RGB -evaluate set 0 +channel out.png
This worked for all my files!

Thanks a lot!

Post Reply