Page 1 of 1

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

Posted: 2010-01-18T01:15:24-07:00
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.

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

Posted: 2010-01-18T10:02:54-07:00
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

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

Posted: 2010-01-18T10:27:32-07:00
by magick
The equivalent of the -define command line option in the MagickWand API is MagickSetOption() and MagickSetImageOption().

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

Posted: 2010-01-18T22:08:06-07:00
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.

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

Posted: 2010-01-18T22:33:05-07:00
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.

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

Posted: 2010-01-19T06:33:15-07:00
by magick
Use MagickSetOption() or MagickSetImageOption(). For example, MagickSetOption(wand,"tiff:rows-per-strip","1");