A better way to do this ?

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
User avatar
Rastalovich
Posts: 6
Joined: 2014-05-24T07:10:00-07:00
Authentication code: 6789

A better way to do this ?

Post by Rastalovich »

Afternoon,

I'm doing my best to fumble around the wiki and so forth to get ImageMagick to do a job for me. In a round about way I'm getting there, but whilst I'm fumbling around, I'd prefer if an expert user read what I'm trying to do - and more or less says "you can do this in one line" or something.

I have a load of images relating to an old game. To cut down on some of the unnecessary things for the game to do, I want to overlay one graphic anim over the other, to produce one anim. Sometimes shadows and a character, or magic anim and an object.

(each anim is a collection of BMPs)

The images are varying sizes, but of the format - Width x Height x 8 bit depth, BMP. Black is the surrounding color of each of these frames, the game counts this as transparent.

So, I'd want to take, BMPfile0(8bit), put BMPfile1(8bit) over the top of it minus the BMPfile1's background cos obvious it'll have a black rectangle with it otherwise. Position BMPfile1 at the foot (south ??). Keeping the bit depth to 8, and the resulting dimensions as the maximum of both.

I've managed thus far to remove the background from BMPfile1, and made a png (following a line in this forum), and I can put that over the BMPfile0 sort of successfully, and IM makes a 24bit bmp as a result. Which then adds another step that I need to reduce it to 8bit or the game will not like it.

Any chance of a 1 line command line for the above ?

Much appreciated (whilst I try other stuff).

Oh, preferably on Windows7 version 6.8.8-8 Q16 x64. (though if necessary I can use any platform)
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: A better way to do this ?

Post by snibgo »

I don't know what you mean by "8-bit depth". Is that total bits per pixel, or bits per channel per pixel? I'll ignore that for now.

The command might be something like:

Code: Select all

convert ^
  in0.bmp ^
  -transparent black ^
  in1.bmp ^
  -gravity south ^
  -composite ^
  out.bmp
This is Windows syntax. Put it in one line if you like, removing each ^ line-continuation marker.

Feel free to put samples somewhere like dropbox.com and paste URLs here.
snibgo's IM pages: im.snibgo.com
User avatar
Rastalovich
Posts: 6
Joined: 2014-05-24T07:10:00-07:00
Authentication code: 6789

Re: A better way to do this ?

Post by Rastalovich »

I've tried something akin to that, but I tried your submission, and you end up with a 32bit bmp file, dimensions of the in1.bmp and the black background of in1.bmp still exists.

For example, this is a pot
http://www.datafilehost.com/d/f02a4c81

.. and this is a blue flame
http://www.datafilehost.com/d/2e19ac57

With the commandline above, I get this:
http://www.datafilehost.com/d/9038fdd6

I'm still playing around, and appreciate the input.
(both of the source files are 8 bit, result is 32 bit)
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: A better way to do this ?

Post by fmw42 »

add -colors 256 at the end to force it to 8bit palette and/or -type palette (or palettealpha if transparency is involved)

assuming the above code is correct for what you need to do, then

Code: Select all

convert ^
  in0.bmp ^
  -transparent black ^
  in1.bmp ^
  -gravity south ^
  -composite ^
  -depth 8
  -colors 256
  out.bmp
-depth 8 makes sure it it 8-bit per channel if on Q16 IM and -colors 256 makes it into palette type of 8-bits total color with a color table

If the above does not do what you want, the upload your two input images and an example output image that looks the way you want to some place like dropbox.com (public folder) and put links to them here.
User avatar
Rastalovich
Posts: 6
Joined: 2014-05-24T07:10:00-07:00
Authentication code: 6789

Re: A better way to do this ?

Post by Rastalovich »

Tried both of those before too.

-depth 8 -colors 256

.. together, seperately, they don't appear to make any difference.

I notice if I use the convert(.exe) command, it favors 32 bit bmp and composite(.exe) favors 24 bit.

Neither of which appear to change the output files' bit depth with the -depth or -colors addition (or both)
User avatar
Rastalovich
Posts: 6
Joined: 2014-05-24T07:10:00-07:00
Authentication code: 6789

Re: A better way to do this ?

Post by Rastalovich »

I think, in fairness, the lesser of my issues is IM ouputting the bmp at the correct depth. If the resulting image is correct, I can use something else to change the depth. Just figured IM would do it.
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: A better way to do this ?

Post by snibgo »

"-colors 256" makes an 8-bit palette BMP file, if that's what you mean.

If you are getting 32-bit, then that probably includes alpha, so "-alpha off" will be useful.

EDIT: Sorry, I meant to add: Your links offer to download .exe files, which I won't do.
snibgo's IM pages: im.snibgo.com
User avatar
Rastalovich
Posts: 6
Joined: 2014-05-24T07:10:00-07:00
Authentication code: 6789

Re: A better way to do this ?

Post by Rastalovich »

Image

Image

Image

I can't believe image hosters are such a pita, most want to conver to another format ffs. The original three links just download for me with no .exe (I'm on a mac atm mind). I've engineered zippyshare for these picks, just right click and save them. Their apache with require you rename the file afterwards.

Can't we go back to things being simple ? >.<
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: A better way to do this ?

Post by fmw42 »

On my Mac OSX Snow Leopard with IM 6.8.9.1 Q16, this works fine for me. Note BMP3: format seems more compatible with palette type results. See http://www.imagemagick.org/Usage/formats/#bmp

in1.bmp is the blue cloud-like image and in2.bmp is the brown insect-like image

Code: Select all

convert in1.bmp \( in2.bmp -transparent black \) -gravity southwest -compose over -composite test1.bmp
identify -verbose test1.bmp
Image: test1.bmp
Format: BMP (Microsoft Windows bitmap image)
Class: DirectClass
Geometry: 68x138+0+0
Units: PixelsPerCentimeter
Type: Palette
Endianess: Undefined
Colorspace: sRGB
Depth: 8-bit
Channel depth:
red: 8-bit
green: 8-bit
blue: 8-bit

Image

So IM says it is type palette, which means 8-bit overall color total.

Windows syntax would be

Code: Select all

convert in1.bmp ( in2.bmp -transparent black ) -gravity southwest -compose over -composite test1.bmp
IM usually takes the format from the first image in the command line. So adding -colors 256 or -type palette should not be needed in this case, but should not hurt to add it.
User avatar
Rastalovich
Posts: 6
Joined: 2014-05-24T07:10:00-07:00
Authentication code: 6789

Re: A better way to do this ?

Post by Rastalovich »

Outstanding fmw42, many thanks for your help and patience.

And adding the -colors 256 gave me 8-bit depth result too.
Post Reply