alpha problem while converting tga to 8 bit png

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
DanielMag1ck
Posts: 2
Joined: 2013-10-17T05:19:32-07:00
Authentication code: 6789

alpha problem while converting tga to 8 bit png

Post 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
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: alpha problem while converting tga to 8 bit png

Post 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.
snibgo's IM pages: im.snibgo.com
User avatar
glennrp
Posts: 1147
Joined: 2006-04-01T08:16:32-07:00
Location: Maryland 39.26.30N 76.16.01W

Re: alpha problem while converting tga to 8 bit png

Post 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.
DanielMag1ck
Posts: 2
Joined: 2013-10-17T05:19:32-07:00
Authentication code: 6789

Re: alpha problem while converting tga to 8 bit png

Post 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
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: alpha problem while converting tga to 8 bit png

Post by snibgo »

You could optimise by putting all operations in a single convert, with no temporary files.
snibgo's IM pages: im.snibgo.com
Post Reply