iPhone - ConvertImageCommand(), MagickWand() in Objective-C.

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
fulvio
Posts: 8
Joined: 2011-09-20T17:59:18-07:00
Authentication code: 8675308

iPhone - ConvertImageCommand(), MagickWand() in Objective-C.

Post by fulvio »

I have the following batch file that works successfully in Windows using "convert.exe"

Code: Select all

@echo off

set SOURCE=input_file.jpg

del output_file.jpg
del source_copy.jpg

conv %SOURCE% -fill "#fff8f2" -colorize 100%% fill.jpg

copy %SOURCE% source_copy.jpg

conv %SOURCE% -modulate 100,0,100 -|^
conv - source_copy.jpg -compose overlay -composite -|^
conv source_copy.jpg - -compose dissolve -define compose:args=37,100 -composite -|^
conv - -modulate 100,70,100 +level 3.5%%,100%% -|^
conv - -channel red -level 0%%,89%% +level 9%%,100%% -|^
conv - -channel green +level 3.5%%,100%% -|^
conv - -channel blue -level 0%%,93%% +level 4.7%%,100%% -|^
conv - -brightness-contrast -5x3 -|^
conv fill.jpg - -compose multiply -gravity center -composite -|^
conv - -level 3.5%%,100%%,0.91 +level 2.7%%,100%% -|^
conv - -channel red +level 3.5%%,100%% -|^
conv - -channel green -level 0%%,87%% +level 1%%,100%% -|^
conv - -channel blue -level 0%%,100%%,0.94 +level 7%%,100%% -|^
conv - -brightness-contrast -1x0 output_file.jpg

del source_copy.jpg
del fill.jpg
At the moment I'm using the following code in Objective-C to achieve the same effect, however I'm a little stuck when it comes to the ConvertImageCommand() method:

Code: Select all

- (void)convertImage {
    MagickWandGenesis();
    magick_wand = NewMagickWand();
    //UIImageJPEGRepresentation([imageViewButton imageForState:UIControlStateNormal], 90);
    NSData * dataObject = UIImagePNGRepresentation([UIImage imageNamed:@"iphone.png"]);
   
    MagickBooleanType status;
    status = MagickReadImageBlob(magick_wand, [dataObject bytes], [dataObject length]);
   
    if (status == MagickFalse) {
        ThrowWandException(magick_wand);
    }

    // Get image from bundle.
    const char *input_image = [[[NSBundle mainBundle] pathForResource:@"iphone" ofType:@"png"] UTF8String];
    const char *output_image = [[[NSBundle mainBundle] pathForResource:@"iphone" ofType:@"png"] UTF8String];

    const char *argv[] = { "convert", input_image, "-resize", "100x100", output_image, NULL };
    // ConvertImageCommand(ImageInfo *, int, char **, char **, MagickExceptionInfo *);
    status = ConvertImageCommand(AcquireImageInfo(), 4, (char**)argv, NULL, AcquireExceptionInfo());

    if (status == MagickFalse) {
        ThrowWandException(magick_wand);
    }
   
    size_t my_size;
    unsigned char * my_image = MagickGetImageBlob(magick_wand, &my_size);
    NSData * data = [[NSData alloc] initWithBytes:my_image length:my_size];
    free(my_image);
    magick_wand = DestroyMagickWand(magick_wand);
    MagickWandTerminus();
    UIImage *image = [[UIImage alloc] initWithData:data];
    [data release];
   
    [imageViewButton setImage:image forState:UIControlStateNormal];
    [image release];
}
Any help would be greatly appreciated. Thanks in advance.
Last edited by fulvio on 2011-09-21T16:11:43-07:00, edited 5 times in total.
User avatar
magick
Site Admin
Posts: 11064
Joined: 2003-05-31T11:32:55-07:00

Re: iPhone - ConvertImageCommand(), MagickWand() in Objectiv

Post by magick »

The argc parameter is an integer that specifies the number of arguments in the argv[] array. The argv[] array contains the command line arguments (e.g. argv[0] = "convert", argv[1] = "image.png", argv[2] = "output.jpg").
fulvio
Posts: 8
Joined: 2011-09-20T17:59:18-07:00
Authentication code: 8675308

Re: iPhone - ConvertImageCommand(), MagickWand() in Objectiv

Post by fulvio »

magick wrote:The argc parameter is an integer that specifies the number of arguments in the argv[] array. The argv[] array contains the command line arguments (e.g. argv[0] = "convert", argv[1] = "image.png", argv[2] = "output.jpg").
Okay, I've updated my code to a resize example, however would you be able to modify it to perform what my batch file performs? Also I'm not quite sure what's means to go into the metadata array (in my case "argc[]").
Last edited by fulvio on 2011-09-21T04:52:31-07:00, edited 1 time in total.
User avatar
magick
Site Admin
Posts: 11064
Joined: 2003-05-31T11:32:55-07:00

Re: iPhone - ConvertImageCommand(), MagickWand() in Objectiv

Post by magick »

Metadata is returned in that array. You can keep it null if you don't care about it.
fulvio
Posts: 8
Joined: 2011-09-20T17:59:18-07:00
Authentication code: 8675308

Re: iPhone - ConvertImageCommand(), MagickWand() in Objectiv

Post by fulvio »

magick wrote:Metadata is returned in that array. You can keep it null if you don't care about it.
Okay, I see. Do you think you'd be able to give me a hand modifying my array to contain what's in my batch file? I'm not quite sure how to create one whole line with all of my properties. Also, I wasn't sure what to put as the integer either (I've placed 2...)?
Post Reply