Another BMP transparency issue

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
petzi69
Posts: 8
Joined: 2016-10-28T22:06:50-07:00
Authentication code: 1151

Another BMP transparency issue

Post by petzi69 »

Since this is my first post here: hi folks!

I'm currently working on some BMP images to mod a game. Because of that, I'm tied to the very specific BMP format that this game accepts.

Step by step:
I take a source BMP of shall we say 800x600 pixel, I -extent it to add some borders (same color as the background). The borders are important!

Next step is to resize the image and turn the background transparent:

Code: Select all

convert source.bmp -fuzz 10% -alpha background -transparent #ec5b18 -resize 99x46 target.bmp
This works fine so far, but the target bmp has a different format as the game wants it. In-game, the whole picture is transparent, not just the background. I already found a solution for this on this forum:

Code: Select all

convert source.bmp  -alpha set -define bmp:format=bmp3 -define bmp3:alpha=true  target.bmp
But after this step, the borders are cropped down to zero pixel at the top and 1 pixel at the bottom border of the target.bmp. It defently happens in the final step, it looked perfect after the -resize.

What I'm I doing wrong, and more important, how I can solve this??
OS: Windows 10
IM: ImageMagick-7.0.3-4-Q16-x86
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Another BMP transparency issue

Post by fmw42 »

It would help if you provide your IM version and platform and also one of your bmp input images and one proper one from the game. You can upload to some place such as dropbox.com and put the URL here. Also provide all your commands for every step including the extending.

Please read the very top most post in this forum at viewtopic.php?f=1&t=9620

What do you mean by the whole picture is transparent?

It is possible if you are on an older version of IM, that one of the defines may be too new.

Also you should put -background #ec5b18 before -alpha background.

You could also try adding either -type truecoloralpha or -type palettealpha before your second command output. It is not yet clear without seeing your proper game image what type it expects for transparency and bit-depth.

This command seems to work for me to make all the background including the extended area transparent and saved as BMP3. Using IM 6.9.6.2 Q16 Mac OSX. Does that import into your game OK?

Code: Select all

convert logo: -background white -gravity center -extent 700x500 -fuzz 10% -transparent white -resize 140x100 -define bmp3:alpha=true BMP3:logo.bmp
petzi69
Posts: 8
Joined: 2016-10-28T22:06:50-07:00
Authentication code: 1151

Re: Another BMP transparency issue

Post by petzi69 »

Put -background #ec5b18 before -alpha background helped. Thanx a lot
OS: Windows 10
IM: ImageMagick-7.0.3-4-Q16-x86
petzi69
Posts: 8
Joined: 2016-10-28T22:06:50-07:00
Authentication code: 1151

Re: Another BMP transparency issue

Post by petzi69 »

Another question.
I would now like to select the non-transparent part of the my image and put a little 'drop-shadow' effect on it. The image should not change the size.

like this: Image
OS: Windows 10
IM: ImageMagick-7.0.3-4-Q16-x86
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: Another BMP transparency issue

Post by snibgo »

snibgo's IM pages: im.snibgo.com
petzi69
Posts: 8
Joined: 2016-10-28T22:06:50-07:00
Authentication code: 1151

Re: Another BMP transparency issue

Post by petzi69 »

Yes, thanks you. The problem is not the shadow, I just don't understand how to select the non-transparent part
OS: Windows 10
IM: ImageMagick-7.0.3-4-Q16-x86
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: Another BMP transparency issue

Post by snibgo »

petzi69 wrote:The problem is not the shadow, I just don't understand how to select the non-transparent part
Why do you want to "select the non-transparent part"? What does that mean?

If the link I showed you doesn't give what you want, please supply an input image that you want a shadow to.
snibgo's IM pages: im.snibgo.com
petzi69
Posts: 8
Joined: 2016-10-28T22:06:50-07:00
Authentication code: 1151

Re: Another BMP transparency issue

Post by petzi69 »

You are to kind. Please forgive me to be so noob!

The image I like to add shadows is this: Image

Since it's a BMP, the transparent parts are not shown in the browser. It seems that at least my firefox can't handle bmp transparency. Never mind, the image is not supossed to be used on the web.
OS: Windows 10
IM: ImageMagick-7.0.3-4-Q16-x86
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Another BMP transparency issue

Post by fmw42 »

try

Code: Select all

magick temp.bmp ^
( -clone 0 -background black -shadow 80x3+3+3 ) ^
-background none -layers merge +repage ^
-define bmp3:alpha=true ^
BMP3:result.bmp
petzi69
Posts: 8
Joined: 2016-10-28T22:06:50-07:00
Authentication code: 1151

Re: Another BMP transparency issue

Post by petzi69 »

I tested the settings as proposed, but changed after a first test to -shadow -shadow 50x1+1+1
Image
Two unexpected things happend: the new image is sized 103x50 pixel instead of 99x46, and the whole image looks much darker now. Just to mention both effects were stronger with the initial settings. Any ideas?
OS: Windows 10
IM: ImageMagick-7.0.3-4-Q16-x86
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Another BMP transparency issue

Post by fmw42 »

-shadow always increases the image size on the left and bottom, so you would have to crop back to the original size. I am not sure why it is darker. My guess is that your tank image is partially transparent everywhere. Let me check.
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Another BMP transparency issue

Post by fmw42 »

In my opinion, this is a bug in -shadow. If I use a red background, the whole tank becomes red. I do not think this should happen. I will report the bug. It also happens with a png input and output.
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Another BMP transparency issue

Post by fmw42 »

Not a bug. My mistake. I forgot the +swap. Try

Code: Select all

magick temp.bmp ^
( -clone 0 -background black -shadow 80x3+3+3 ) ^
+swap -background none -layers merge +repage ^
-define bmp3:alpha=true ^
BMP3:result.bmp
petzi69
Posts: 8
Joined: 2016-10-28T22:06:50-07:00
Authentication code: 1151

Re: Another BMP transparency issue

Post by petzi69 »

Code: Select all

temp.bmp ( -clone 0 -background black -shadow 80x1+1+1 ) ^
+swap -background none -layers merge +repage ^
-crop 99x46+0+0 -define bmp3:alpha=true BMP3:result.bmp

That's the magic formula! Now I run some hundred images through my batch process :)! Thank you very much!

Image
OS: Windows 10
IM: ImageMagick-7.0.3-4-Q16-x86
Post Reply