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?".
Hi I'm trying to convert a bunch of png files to jpg from one folder. But some are transparent so I don't want to convert those.
I'm on Windows and using the command line. What I have found is this:
Which will convert all of the png's to jpg's
I also found "%[opaque]" which should return 1 if it is transparent but I don't know how to combine these two statements. I basically want it to skip all png files that are transparent.
Any help would be appreciated.
malbertmalbert wrote:I also found "%[opaque]" which should return 1 if it is transparent
Where did you find that? It's wrong. "%[opaque]" returns the string "true" if the image is fully opaque; otherwise (if fully or partly transparent) it returns "false".
I would write a for-loop that loops through the png files. For each one, use "identify -format %[opaque]" to see if it is opaque. If it is, do the conversion.
rem Convert *.png files that are fully opaque.
setlocal enabledelayedexpansion
for %%i in (*.png) do (
echo %%i
for /F "usebackq" %%F in (`identify -format %%[opaque] %%i`) do set OP=%%F
echo !OP!
if "!OP!"=="true" convert %%i %%~ni.jpg
)
if "!OP!"=="true" convert %%i %%~ni.jpg>>changedimages.txt
Added ">>changedimages.txt" to output the name of a file that it changed to a text file, but it only creates the text file and doesn't write anything to it. I need this so I can keep track of the files that are changed.
It would be best if after it appends a file's name to go to the next line as well if that is possible. Any ideas?