Page 1 of 1

Create transparent background PNG for mostly whitish

Posted: 2009-01-15T15:25:11-07:00
by richardchaven
I have images that I am converting to PNG with transparent backgrounds. Sadly, their current background is not always pure white: sometimes it's almost white.

Can I specify a range of colors that I want to be transparent in one operation?

Ideally, I want to specify an color increment. I.M. would start at the upper-left pixel's color and check "inwards" from all sides looking for adjacent pixels that are different by that increment, and would make that the border between the transparent background and the (visible) image subject.

Any ideas ?

Re: Create transparent background PNG for mostly whitish

Posted: 2009-01-15T20:00:38-07:00
by fmw42

Re: Create transparent background PNG for mostly whitish

Posted: 2009-01-15T20:50:41-07:00
by richardchaven
For what it's worth, here is the working Windows batch file that takes a (dropped) file and creates a version with a transparent background (or at least a transparent color replacement)

Code: Select all

@echo OFF
if [%1]==[] goto usage
if not exist %1 goto usage
set ERRORLOGFILE="C:\Program Files\ImageMagick-6.4.8-Q16\LastRunError.Log"
del /q %ERRORLOGFILE%
if [%2]==[] set TCOLOR=white	
if not [%2]==[] set TCOLOR=%2
if not [%3]==[] set TARGET=%3
if [%3]==[] set TARGET="%~dpn1-transparent%~x1"
for %%A in (%TARGET%) do if %%~xA==.jpg set TARGET="%%~dpnA.png"
"C:\Program Files\ImageMagick-6.4.8-Q16\convert" "%1" -fuzz 10%% -transparent %TCOLOR% -strip %TARGET% 2>%ERRORLOGFILE%
set TCOLOR=
set TARGET=
if not exist %ERRORLOGFILE% goto end
for %%A in (%ERRORLOGFILE%)  do if %%~zA equ 0 goto end
notepad.exe %ERRORLOGFILE%
goto end
:usage
echo usage "%~nx0" ^<input filename^> [^<background color^> [^<output filename^>]]
:end
Thank you for all your help