I have a command line that works but want it as a program

The MagickWand interface is a new high-level C API interface to ImageMagick core methods. We discourage the use of the core methods and encourage the use of this API instead. Post MagickWand questions, bug reports, and suggestions to this forum.
Post Reply
garturosm

I have a command line that works but want it as a program

Post by garturosm »

Hello.

Following the examples in the ImageMagick site I was able to execute this command:

convert my_img.jpg -define tiff:rows-per-strip=1 -depth 1 -background black -flatten -compress Group4 out_img.tif

it converts a jpeg image (8 bits) to tiff format (1 bit) with group 4 compression, I liked it :) .

Now I'm trying to do a program using MagickWand API but have no idea how to traslate these options of the command line to the program:

-define tiff:rows-per-strip=1
-background black
-flatten
-compress Group4

I used the function: MagickSetImageDepth(wand, 1) to implement the -depth 1 option and I get the output file in black and white (correctly). I tryed other functions like:

MagickSetImageCompression(wand, Group4Compression ) and MagickSetImageBackgroundColor for the other options but the image is not compressed :( .

Any help will be very welcome.

Kind Regards.
el_supremo
Posts: 1015
Joined: 2005-03-21T21:16:57-07:00

Re: I have a command line that works but want it as a program

Post by el_supremo »

Code: Select all

	// -flatten (note that this creates a new wand with the flattened image)
	new_wand = MagickMergeImageLayers(wand,FlattenLayer);
	
	// -background black
	PixelWand *pw = NULL;
	pw = NewPixelWand();
	PixelSetColor(pw,"black");
	MagickSetBackgroundColor(wand,pw);
	
	// -compress Group4
	// See also: http://www.imagemagick.org/discourse-server/viewtopic.php?f=6&t=6717
	MagickSetImageCompression(wand,Group4Compression);
	
	// -depth 1
	MagickSetImageDepth(wand,1)
I don't know how to do the -define. Magick will have to help with that one.

Pete
Sorry, my ISP shutdown all personal webspace so my MagickWand Examples in C is offline.
See my message in this topic for a link to a zip of all the files.
User avatar
magick
Site Admin
Posts: 11064
Joined: 2003-05-31T11:32:55-07:00

Re: I have a command line that works but want it as a program

Post by magick »

The equivalent of the -define command line option in the MagickWand API is MagickSetOption() and MagickSetImageOption().
garturosm

Re: I have a command line that works but want it as a program

Post by garturosm »

Hello el_supremo, thanks for your reply, I have added the code for:

// -background black
PixelWand *pw = NULL;
pw = NewPixelWand();
PixelSetColor(pw,"black");
MagickSetBackgroundColor(wand,pw);

// -compress Group4
// See also: viewtopic.php?f=6&t=6717
MagickSetImageCompression(wand,Group4Compression);

// -depth 1
MagickSetImageDepth(wand,1) // I had this already

It works well (don´t throw any exception) but the resulting image is not compressed (it's larger than the original). When compressed (with the command line) is it about 7k and the image I'm getting is about 88 k. I will wait to see if there is a post from Magick. I also checked the reference you tell me regardind G4 compression.

Thank you again.
garturosm

Re: I have a command line that works but want it as a program

Post by garturosm »

Thanks admin,

could you please post the example of the -define tiff:rows-per-strip=1 option using WandAPI?

Because most of the documentation and forum is about the convert command line and haven´t found some example of it.

Kind Regards.
User avatar
magick
Site Admin
Posts: 11064
Joined: 2003-05-31T11:32:55-07:00

Re: I have a command line that works but want it as a program

Post by magick »

Use MagickSetOption() or MagickSetImageOption(). For example, MagickSetOption(wand,"tiff:rows-per-strip","1");
Post Reply