Page 1 of 1

alpha problem while converting tga to 8 bit png

Posted: 2013-10-17T05:35:20-07:00
by DanielMag1ck
Hi community!

I'm having a small problem while converting a tga to png. The png should be 25% of the original size. Also be an 8 bit png. So far. The only problem now is, that IM cuts too many pixels.

Here is what I am doing. The filenames are just placeholders, coz this is running in a script and is called step by step:
  • convert -alpha background -background "#757834" -alpha off $source_filepath $temp1_filepath
    convert -resize 25% -sharpen 0x0.6 -quantize srgb -colors 255 $temp1_filepath $temp1_filepath
    convert -resize 25% -dither None -quantize srgb -colors 255 $source_filepath $temp2_filepath
    composite -compose CopyOpacity $temp2_filepath $temp1_filepath $target_filepath
    convert -define png:format=png8 $target_filepath $target_filepath
    convert -trim $target_filepath $target_filepath
Unfortunately I cant upload an image here to show you the input / output. Just imagine a globe made of steel having several braces. These braces are cutted of, because they are at the output only two pixels of width.

Any idea how to solve this problem? Would be really great if someone can help me with that, coz am not an expert with this.


Thanks a lot

Re: alpha problem while converting tga to 8 bit png

Posted: 2013-10-17T08:23:33-07:00
by snibgo
The general syntax of convert is:

Code: Select all

convert input_file operations_that_change_the_image output_file
So your syntax is generally wrong.

Re: alpha problem while converting tga to 8 bit png

Posted: 2013-10-17T08:45:03-07:00
by glennrp
DanielMag1ck wrote: These braces are cutted of, because they are at the output only two pixels of width.
Maybe apply some blur to widen the braces a little.

Re: alpha problem while converting tga to 8 bit png

Posted: 2013-10-17T12:27:51-07:00
by DanielMag1ck
snibgo wrote:The general syntax of convert is:

Code: Select all

convert input_file operations_that_change_the_image output_file
So your syntax is generally wrong.
It is working the other way to. Otherwise I wouldn't have get an output.

I finally found the solution...

convert -alpha background -background "#757834" -alpha off $source_filepath $temp1_filepath
convert -resize 25% -quantize srgb -colors 255 $temp1_filepath $temp1_filepath
convert -resize 25% -dither None -quantize srgb -channel a -threshold 52% -colors 255 $source_filepath $temp2_filepath
composite -compose CopyOpacity $temp2_filepath $temp1_filepath $target_filepath
convert -trim -colors 255 $target_filepath png8:$target_filepath

If there can be something optimized, you're welcome. All this just came up while trying it out.

Greetings

Re: alpha problem while converting tga to 8 bit png

Posted: 2013-10-17T12:33:30-07:00
by snibgo
You could optimise by putting all operations in a single convert, with no temporary files.